Jump to content

Sessions are killing me


kevinak

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.