ShaolinF Posted January 24, 2008 Share Posted January 24, 2008 Hi Guys, I created some session variables and was planning on using them on another page. But they don't seem to be getting passed over. See code below: page1.php - Session created and works fine If(!isset($_SESSION['LOGGEDIN'])) // If user does not have a session { //Add session $_SESSION['NAME'] = $_POST['name']; } page2.php - output session, value is nothing. session_start(); echo "name:" . $_SESSION['NAME'] . "<BR>"; die; Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/ Share on other sites More sharing options...
PHP Monkeh Posted January 24, 2008 Share Posted January 24, 2008 do you have session_start() on page1.php aswell (sorry if that sounds like a stupid question but I have to make sure). Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448281 Share on other sites More sharing options...
ShaolinF Posted January 24, 2008 Author Share Posted January 24, 2008 yes. Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448286 Share on other sites More sharing options...
PHP Monkeh Posted January 24, 2008 Share Posted January 24, 2008 Is the if() statement actually working? Put an echo in your page1.php if() and see if it appears on the page, because that's the only thing I can see which is wrong with it. Unless your $_POST['name'] is empty. Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448288 Share on other sites More sharing options...
revraz Posted January 24, 2008 Share Posted January 24, 2008 I dont know why you are checking their session to set a session, why dont you just set them both when they log in. Besides that, make sure session_start() is the first thing in both your pages and check your session save path to make sure it's correct. Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448290 Share on other sites More sharing options...
ShaolinF Posted January 24, 2008 Author Share Posted January 24, 2008 I found the problem, now I need to find another way around it. <FORM> <INPUT type="button" class="altButtonFormat" value="Start Over" onClick="location.href='index.htm?id=<?php include("rand.htm"); session_unset(); session_destroy(); ?>'"> </FORM> The point of that was so when they click the link it would redirect the to the home page and destroy the session. :-\ Do you guys have any other suggestions on how I could achieve this ? Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448298 Share on other sites More sharing options...
revraz Posted January 24, 2008 Share Posted January 24, 2008 If you want to maintain their username, just reset the session variable you want to reset instead of all of them and destroying it. Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448302 Share on other sites More sharing options...
phpSensei Posted January 24, 2008 Share Posted January 24, 2008 edit: already said... Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448303 Share on other sites More sharing options...
ShaolinF Posted January 24, 2008 Author Share Posted January 24, 2008 If you want to maintain their username, just reset the session variable you want to reset instead of all of them and destroying it. Well there are about dozen other variables involved, I only included one for the sake of simplicity. It's a purchase system. The user has the choice of starting over which will reset all the variables. Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448304 Share on other sites More sharing options...
PHP Monkeh Posted January 24, 2008 Share Posted January 24, 2008 Find out which variables you want to reset and just unset() them individually: <?php unset($_SESSION['session']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448307 Share on other sites More sharing options...
revraz Posted January 24, 2008 Share Posted January 24, 2008 Probably easier to use some type of numerical sequence instead then and just use a loop to reset just those. Or write the username as a cookie instead. Quote Link to comment https://forums.phpfreaks.com/topic/87645-sessions/#findComment-448318 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.