kevinak Posted September 3, 2008 Share Posted September 3, 2008 Ok, I've searched and searched but I can't figure out how to make sessions work for what I need We have two pages. 1. Confirm page 2. Reward Page I tried setting a session on the Confirm page with this code. <?php $_SESSION['OMG']= 'on'; session_start(); ?> I think that's right. Now I need to call that session and check if it is set, if it is then I want the user to get the reward on the rewards page. If it's not I want an error to come up. Then I need the session to destory itself or reset to nothing so they can't refresh or simply change the url to get a different reward without going through the confirm page. In other words. I want them to first go to the confirm page at all times. No way around it. <?php session_name(); session_start(); ?> This is what I used to call the sessions on the Rewards Page. (I'm very new to sessions) Then my if is simply this if (!isset($_SESSION['OMG'])) { //error here } else { //reward here } Thank you for reading and for any responses Link to comment https://forums.phpfreaks.com/topic/122562-sessions-are-killing-me/ Share on other sites More sharing options...
genericnumber1 Posted September 3, 2008 Share Posted September 3, 2008 session_start() has to be before you do pretty much anything with sessions.. session_start(); $_SESSION['foo'] = 'bar'; then, on a later page you call it after session_start(); session_start(); echo $_SESSION['foo']; as for your implementation, hopefully you can derive it from this explanation of sessions. Link to comment https://forums.phpfreaks.com/topic/122562-sessions-are-killing-me/#findComment-632802 Share on other sites More sharing options...
Fadion Posted September 3, 2008 Share Posted September 3, 2008 confirm page <?php session_start(); //session_start() comes first $_SESSION['confirmed'] = 'yeah baby'; ?> reward page <?php session_start(); //session_start() comes first here too if(isset($_SESSION['confirmed'])){ echo 'yeah baby. here is your award'; } else{ echo 'nah, youre cheating'; } ?> EDIT: genericnumber1 beat me to it, but i'm posting this anyway Link to comment https://forums.phpfreaks.com/topic/122562-sessions-are-killing-me/#findComment-632806 Share on other sites More sharing options...
kevinak Posted September 3, 2008 Author Share Posted September 3, 2008 You guys are the best seriously Very fast and super knowledgeable. Thank you so much. I'm going to put these up right away Oh and if any of you see this. How would I then destory the session? Do I use the session_destroy() function? Link to comment https://forums.phpfreaks.com/topic/122562-sessions-are-killing-me/#findComment-632821 Share on other sites More sharing options...
Cosizzle Posted September 3, 2008 Share Posted September 3, 2008 Here ya go! <?php session_start(); $_SESSION = array(); session_destroy(); ?> Link to comment https://forums.phpfreaks.com/topic/122562-sessions-are-killing-me/#findComment-632865 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.