Jump to content

[SOLVED] $_POST, $_GET, Sessions, and the "Back" button


Moron

Recommended Posts

Page 1: The user logs in with employee number and password (their SSN).

 

Page 2: A main menu displays with Leave History, Paystubs, and Dental reimbursement.

 

These pages work individually, but how can I link back to the main menu by passing their employee number and SSN back there, without making them have to log in again?

 

I've tried several methods of $_POST and $_GET. No luck so far.

 

 

Link to comment
Share on other sites

Well, use sessions, like you mentioned in the title.

 

I'm using sessions. For example, on the main menu page, I establish sessions so that they can click the other three pages and these pass fine. For some reason, though, I'm having a problem passing them back to the main menu page.

 

In other words, they're passing forward just fine but I can't seem to get them to pass back. Do I need to convert a session variable back into a $_POST variable at some point?

 

 

 

Link to comment
Share on other sites

What? What do you mean pass back? We need a specific example with code.

 

For example, after they've logged in, employeeinformationmenu.php has the following at the top:

 

session_start();
$_SESSION['password'] = $_POST['password'];
$_SESSION['empcode'] = $_POST['empcode'];

 

From there, they can click on Dental/Vision/Hearing, which is dentalvisionhearing.php. At the top, dentalvisionhearing.php has:

 

session_start();
$empcode = $_POST['EMPNO'];
$_SESSION['empcode']=$empcode;
$SESSION['password'] = $_POST['password'];

 

So how can I make a proper link back to employeeinformationmenu.php? Does the link back need to be a form, possibly?

 

By the way, my query in employeeinformationmenu.php contains:

 

WHERE ((M2.[EMPNO] = '".$_POST['empcode']."' and 
M2.[MSSNO] = '".$_POST['password']."') or (M2.[MSSNO] = '".$_SESSION['password']."' and M2.[EMPNO] = '".$_SESSION['empcode']."'))

 

When I use the link back to employeeinformationmenu.php, it goes to the "die" part. I know the input is right or it wouldn't have given me anything in employeeinformationmenu.php in the first place. So I'm thinking that something isn't carrying over properly in my sessions.

 

Thanks!

 

 

 

 

 

Link to comment
Share on other sites

For example, after they've logged in, employeeinformationmenu.php has the following at the top:

 

session_start();
$_SESSION['password'] = $_POST['password'];
$_SESSION['empcode'] = $_POST['empcode'];

 

 

just a little note..

if you goto the page with the above code and you have NOT summited a post your wipeout the sessions, (over write with nothing)

 

try this

session_start();
if(isset($_POST['password'])) {$_SESSION['password'] = $_POST['password'];}
if(isset($_POST['empcode'])) {$_SESSION['empcode'] = $_POST['empcode'];}

Link to comment
Share on other sites

For example, after they've logged in, employeeinformationmenu.php has the following at the top:

 

session_start();
$_SESSION['password'] = $_POST['password'];
$_SESSION['empcode'] = $_POST['empcode'];

 

 

just a little note..

if you goto the page with the above code and you have NOT summited a post your wipeout the sessions, (over write with nothing)

 

try this

session_start();
if(isset($_POST['password'])) {$_SESSION['password'] = $_POST['password'];}
if(isset($_POST['empcode'])) {$_SESSION['empcode'] = $_POST['empcode'];}

 

That did the trick. Now I can go "back" (with a link) to employeeinformationmenu.php without losing the session.

 

Thanks!

 

Link to comment
Share on other sites

Why does dental have the $_POST stuff? Once you store something in the session you don't have to keep setting it again.

And what die part?

 

Also $SESSION is wrong, it's $_SESSION.

 

The $_POST was from some older code when I was just starting with php and was even more clueless than I am now!  :)

 

As for the "die" part, it basically brings up some instructions if they get their employee number or SSN wrong, or of they don't match.

 

Thanks!

 

 

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.