Re: PHP Session problem...

From: Date: Sun, 04 May 2003 21:10:16 +0000
Subject: Re: PHP Session problem...
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-19759@lists.php.net to get a copy of this message
Well first of all, get rid of automatic redirection. Then, I suggest outputting "messages" to the browser so you can see what is happening. For example: Creating session variables: (i am explicitly calling session_start()) $row = mysql_fetch_array($result, MYSQL_BOTH); $_SESSION["uid"] = trim($row[0]); print '$_SESSION["uid"] ='.$_SESSION["uid"].'<br>Input was '.trim($row[0]).'<br>'; $_SESSION["uname"] = trim($row[1]); print '$_SESSION["uname"] ='.$_SESSION["uname"].'<br>Input was '.trim($row[1]).'<br>'; print 'Session ID is: '.session_id().'<br>'; //header("Location: bohome.php?"); The most imporant thing is to make sure that a) the values are going in and that b) the session id which is output to the browser is EXACTLY the same in both pages! session_start(); ob_start(); $userid = trim($_SESSION["uid"]); $username = trim($_SESSION["uname"]); if( $userid == "" ) { print 'Session ID is: '.session_id().'<br>'; //header("Location: index.php?msg=err&" . $userid); exit; } I use print statements, you may be familiar with echo instead. You may do which ever you wish. Using output messages like this is perhaps THE SINGLE most important skill to learn when programming. It makes finding errors easier and faster, and also helps to pinpoint bugs :-) Stephen ----- Original Message ----- From: "Guru P Chaturvedi" <bangboy2k2@hotmail.com> To: <php-windows@lists.php.net> Sent: Sunday, May 04, 2003 9:51 PM Subject: [PHP-WIN] PHP Session problem... > hi all, > > i'm really really confused and fed up of the PHP sessions. it works > sometimes and fails horribly rest of the times. please take a look at the > code: > > Creating session variables: (i am explicitly calling session_start()) > > $row = mysql_fetch_array($result, MYSQL_BOTH); > > $_SESSION["uid"] = trim($row[0]); > $_SESSION["uname"] = trim($row[1]); > > header("Location: bohome.php?"); > > it get's thru very well and get's redirected to bohome.php > > if that file i have this peice of code: > > session_start(); > ob_start(); > > $userid = trim($_SESSION["uid"]); > $username = trim($_SESSION["uname"]); > > if( $userid == "" ) > { > header("Location: index.php?msg=err&" . $userid); > exit; > } > > here the $userid is becoming "" and thus redirects back to index page. why > is this behaving so... what cud be the problem...? please help me out.... > > regards, > guru. > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.windows (#19759) next »