passing session variables through URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

passing session variables through URL

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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>
Post Reply