Page 1 of 1

passing session variables through URL

Posted: Thu Aug 18, 2005 11:48 am
by bwv2
I want to set a session variable by passing it to another page through a URL. The URL is set in a POST form. Here is what I have written:

Code: Select all

<form 
METHOD="POST" action= "./step.php?$_SESSION['nextPage']=setup">
<input type="image" src="./images/settings.png" value="setup" name="setup">
</form>
When this form is submitted the page loads with the URL looking like:
http://www.theSite/step.php?$_SESSION['nextPage']=setup

However, the $_SESSION var is not changed. Is there some other syntax I must put in to make it change as the page is passed?

Alternatively I could just look on the next page for the $_POST['setup'] variable, but this doesn't work either. Does this all have something to do with the fact that my button is an image? I wouldn't think so. Let me know if you have any clues. Thanks.

Posted: Thu Aug 18, 2005 11:51 am
by josh

Code: Select all

<form
METHOD="POST" action= "step.php">
<input type="image" src="./images/settings.png" value="setup" name="setup">
<input type="hidden" name="step" value=<?=$_SESSION['step']?>">
</form>

Posted: Thu Aug 18, 2005 11:53 am
by feyd
if it's a session variable, you already have it on the next page.

anyways, the reason why it's not replaced is because you aren't in php when you output that HTML.

Code: Select all

<form
METHOD="POST" action= "./step.php?<?php echo $_SESSION['nextPage']; ?>=setup">
<input type="image" src="./images/settings.png" value="setup" name="setup">
</form>