Re: Session problem

From: Date: Thu, 31 Mar 2005 12:09:57 +0000
Subject: Re: Session problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-211951@lists.php.net to get a copy of this message
* 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

« previous php.general (#211951) next »