avingard Posted June 11, 2008 Share Posted June 11, 2008 I have the following problem on one page I have this code: session_start(); $_SESSION['var']; header("location:page2.php"); I've commented out the header line and tested to make sure var registers, and it does on that page, but as soon as I redirect the page, I have this code first thing on page2 if(isset("$_SESSION['var']")) { //codecode } the problem is, isset ALWAYS returns false. What's happening to var? Link to comment https://forums.phpfreaks.com/topic/109678-session-variables-disapearing/ Share on other sites More sharing options...
jonsjava Posted June 11, 2008 Share Posted June 11, 2008 you need to add session_start(); on your other page. you can't get session variables unless your session continues. session_start(); doesn't mean start the session for the first time, it means start the session for this page. (layman's terms) Link to comment https://forums.phpfreaks.com/topic/109678-session-variables-disapearing/#findComment-562790 Share on other sites More sharing options...
kenrbnsn Posted June 11, 2008 Share Posted June 11, 2008 You need to call "session_start()" in every script where you use sessions. Ken (beaten ... ) Link to comment https://forums.phpfreaks.com/topic/109678-session-variables-disapearing/#findComment-562791 Share on other sites More sharing options...
PFMaBiSmAd Posted June 11, 2008 Share Posted June 11, 2008 Also, this line of code does nothing - $_SESSION['var']; You need to make an assignment to a variable to cause it to exist or to have a value - $_SESSION['var'] = ""; // or $_SESSION['var'] = 123; Link to comment https://forums.phpfreaks.com/topic/109678-session-variables-disapearing/#findComment-562798 Share on other sites More sharing options...
avingard Posted June 11, 2008 Author Share Posted June 11, 2008 Thanks tons. Now I know Link to comment https://forums.phpfreaks.com/topic/109678-session-variables-disapearing/#findComment-562810 Share on other sites More sharing options...
l0ve2hat3 Posted June 11, 2008 Share Posted June 11, 2008 Also, there is no need for the quotations surrounding the session variable in the isset function. you have: if(isset("$_SESSION['var']")) Should be: if(isset($_SESSION['var'])) Link to comment https://forums.phpfreaks.com/topic/109678-session-variables-disapearing/#findComment-562817 Share on other sites More sharing options...
hamza Posted June 11, 2008 Share Posted June 11, 2008 Dear Firstly you need to start the session as you do secondly you need to give it a value to see on different pages like one person shown above $_SESSION[' anyvarialbe'] = 'value or variable you like to give here '; and isset() and empty() both works same but better is to use the empty() because it is much better then isset() function. and always use like this in the following funtions empty( $_SESSION[' ']) header("Location: redirct_pagename.php"); is the correct syntax to use. hope you get the point Link to comment https://forums.phpfreaks.com/topic/109678-session-variables-disapearing/#findComment-562989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.