huiling25 Posted July 16, 2007 Share Posted July 16, 2007 I am making a e-shopping kind of website. Using dreamweaver mx2004, IIS server, mysql5.0, php5. i hand-code my log in user. however, i realised tt when the page redirect ito another page, the session is empty. but the page tt is checking my log in, the session has the username. but after redirecting (using header), the session becomes empty. This is my code: $_SESSION['user']=$username; header("Location: ./test.php"); Can anyone helped me? Link to comment https://forums.phpfreaks.com/topic/60225-help-on-sessions/ Share on other sites More sharing options...
trq Posted July 16, 2007 Share Posted July 16, 2007 Have you called session_start() on both pages? Link to comment https://forums.phpfreaks.com/topic/60225-help-on-sessions/#findComment-299587 Share on other sites More sharing options...
huiling25 Posted July 16, 2007 Author Share Posted July 16, 2007 Yes, i did, at the top of all the codes on this 2 pages. Link to comment https://forums.phpfreaks.com/topic/60225-help-on-sessions/#findComment-299588 Share on other sites More sharing options...
rameshfaj Posted July 17, 2007 Share Posted July 17, 2007 Your code: $_SESSION['user']=$username; header("Location: ./test.php"); After u have ensured that u have used session_start() in both the pages. You need to check if the variable $username is holding any value or not.If this variable is set to somevalue then the session variable holds it.What if this variable is set to null ?This situation might have occured to ur code.Plz check once!!! Link to comment https://forums.phpfreaks.com/topic/60225-help-on-sessions/#findComment-299998 Share on other sites More sharing options...
huiling25 Posted July 17, 2007 Author Share Posted July 17, 2007 Hmm, $username is taken from the log in form textbox byt $_POST['username']. I managed to get the session printed out correctly on checklogin.php~ but from checklogin page to test.php by the redirecting using header, test.php has the session as empty again. Link to comment https://forums.phpfreaks.com/topic/60225-help-on-sessions/#findComment-300069 Share on other sites More sharing options...
teng84 Posted July 17, 2007 Share Posted July 17, 2007 put session start on every page you need session Link to comment https://forums.phpfreaks.com/topic/60225-help-on-sessions/#findComment-300072 Share on other sites More sharing options...
huiling25 Posted July 17, 2007 Author Share Posted July 17, 2007 Yes, i did put session_start() on top of all the codes in every page needed for the session. Link to comment https://forums.phpfreaks.com/topic/60225-help-on-sessions/#findComment-300076 Share on other sites More sharing options...
huiling25 Posted July 18, 2007 Author Share Posted July 18, 2007 I had tried doing this: checklogin.php <?php session_start(); $_SESSION['user']='John'; header("Location: ./test.php"); ?> test.php <?php session_start();?> <html> <head> </head> <body> Hello, <?php echo $_SESSION['user'];?> </body> </html> But on test.php, the result i see is only Hello, Link to comment https://forums.phpfreaks.com/topic/60225-help-on-sessions/#findComment-300801 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.