You are here: Re: Session problem « PHP « IT news, forums, messages
Re: Session problem

Posted by Matthew Weier O'Phinney on 03/31/05 15:09

* Rosen <r.marinov@gmail.com>:
> Hi,
> I have this code :
>
> ========
> page1.php:
> <?
>
> $nfo["fu"]="12";
>
> session_start();
> session_register(nfo);

As of PHP 4.1.0, you no longer need to use session_register(); you can
simply add items to the $_SESSION superglobal array:

$_SESSION['nfo'] = $nfo;

Visit http://php.net/session for more information.

> $sn=session_name();
> $nn=session_id() ;
>
> $web="page2.php?lang=en";
> $web.="&$sn=$nn";
>
> header("Location: $web");
> ?>
> ===============
> page2.php:
> <?
> session_start();
> global $nfo;

This only works if you have register_globals on -- which you probably
shouldn't. A better, more portable way to do this would be:

$nfo = array();
if (isset($_SESSION['nfo'])) {
$nfo = $_SESSION['nfo']
}

> $uss=$nfo["fu"];
>
> echo $uss; //// HERE $uss is empty!

You should probably check for the existence of the 'fu' key in the array
before doing this.

$uss = null;
if (isset($nfo['fu'])) {
$uss = $nfo['fu'];
}

if (empty($uss)) {
echo "Missing vital session info";
die;
}

echo $uss;

> This script works on several linux servers, but on one doesn't work (
> variable $uss in page2.php has no value ).
> I think this may be problem with PHP configuration on this server ( I don't
> have root password for this server ).

I've pointed out my recommendations above.

--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:matthew@garden.org | http://vermontbotanical.org

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация