rakyy Posted May 9, 2012 Share Posted May 9, 2012 i have Created a Session with this code $_SESSION['USER_NAME'] = trim($_POST['username']) How can i access the $_SESSION['USER_NAME'] in other Pages ; and will this code for $var = $_SESSION[uSER_NAME] can i get the SESSIOn value in " $var" variable ?? Quote Link to comment https://forums.phpfreaks.com/topic/262304-can-i-assign-normal-variables-the-value-of-my-session-variable/ Share on other sites More sharing options...
scootstah Posted May 9, 2012 Share Posted May 9, 2012 How can i access the $_SESSION['USER_NAME'] in other Pages ; Just like that. and will this code for $var = $_SESSION[uSER_NAME] can i get the SESSIOn value in " $var" variable ?? Yes, though make sure to use quotes between the square brackets otherwise you will get an error. $_SESSION['USER_NAME'] not $_SESSION[uSER_NAME] Also, make sure you have session_start at the top of your script. In order to work with sessions, this function MUST have been called. Quote Link to comment https://forums.phpfreaks.com/topic/262304-can-i-assign-normal-variables-the-value-of-my-session-variable/#findComment-1344218 Share on other sites More sharing options...
rakyy Posted May 9, 2012 Author Share Posted May 9, 2012 when i try To Echo $var ; i cant see anything Quote Link to comment https://forums.phpfreaks.com/topic/262304-can-i-assign-normal-variables-the-value-of-my-session-variable/#findComment-1344221 Share on other sites More sharing options...
Jessica Posted May 9, 2012 Share Posted May 9, 2012 Turn on error reporting; Quote Link to comment https://forums.phpfreaks.com/topic/262304-can-i-assign-normal-variables-the-value-of-my-session-variable/#findComment-1344223 Share on other sites More sharing options...
rakyy Posted May 9, 2012 Author Share Posted May 9, 2012 Error Reporting is On Quote Link to comment https://forums.phpfreaks.com/topic/262304-can-i-assign-normal-variables-the-value-of-my-session-variable/#findComment-1344233 Share on other sites More sharing options...
scootstah Posted May 9, 2012 Share Posted May 9, 2012 Have you placed session_start() at the top of your script? Quote Link to comment https://forums.phpfreaks.com/topic/262304-can-i-assign-normal-variables-the-value-of-my-session-variable/#findComment-1344236 Share on other sites More sharing options...
rakyy Posted May 9, 2012 Author Share Posted May 9, 2012 yeh i have session_start() @top of the Page Is there any way by hich i can find out whether my Session is working properly !! Quote Link to comment https://forums.phpfreaks.com/topic/262304-can-i-assign-normal-variables-the-value-of-my-session-variable/#findComment-1344238 Share on other sites More sharing options...
scootstah Posted May 9, 2012 Share Posted May 9, 2012 You need to have session_start() on both pages - the one where you set the session, and the one where you are trying to receive the session. It's easy enough to test, just make these two files: setsession.php <?php session_start(); $_SESSION['foo'] = 'bar'; getsession.php <?php session_start(); echo $_SESSION['foo']; Quote Link to comment https://forums.phpfreaks.com/topic/262304-can-i-assign-normal-variables-the-value-of-my-session-variable/#findComment-1344241 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.