Hi, I want to preserve the session id, via URL transmission, across three pages, (from page 1 to page 2, and then page 3) but I can only get it to last for two pages, even though the code is basically the same. (I can’t use javascript or cookies for this app.)
Once I go from the second page to the third, I get a new session id no matter what. Any help would be appreciated!
php v5.2.14 , session.auto_start is off
Here’s page 1 (pledge1.php):
<?php
ini_set('session.use_cookies',0);
session_start();
?>
<html>
<body>
<?php
//if form has been submitted, validate data, store it in session, go to pledge review page
if (isset($_POST['ReviewPledge'])) {
$_SESSION['amount'] = $_POST['amount'];
$url="Location: pledge2.php?".htmlentities(session_name().'='.session_id());
session_write_close();
header("$url");
exit();
}
?>
<?php
echo "session_id(): ".session_id();
echo "<br>SID: ".htmlspecialchars(SID);
echo "<p>"
?>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
Monthly pledge amount:
<label>
<input type="text" name="amount" id="amount" size="2" maxlength="2" value="<?php echo htmlspecialchars($_SESSION['amount']); ?>">
</label>
<p>
<label>
<input style="font-size:20"; type="submit" name="ReviewPledge" value="Submit pledge data">
</label>
</form>
</body>
</html>
page 2 (pledge2.php):
<?php
ini_set('session.use_cookies',0);
session_id($_GET[htmlentities(session_name())]);
session_start();
?>
<?php
//if the 'Submit my pledge' button was clicked, proceed
// for some reason the stupid link action method isn't working! :S
if(isset($_POST['SubmitPledge'])) {
$url="Location: pledge3.php?".htmlentities(session_name().'='.session_id());
session_write_close();
header("$url");
exit();
}
?>
<html>
<body>
<?php
echo "session_id(): ".session_id();
echo "<br>SID: ".htmlspecialchars(SID);
echo "<p>"
?>
You have pledged: $
<?php
echo $_SESSION['amount'];
?>
<FORM METHOD="LINK" ACTION="pledge1.php">
<INPUT TYPE="submit" VALUE="Go back and change pledge info.">
</FORM>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input style="font-size:20"; type="submit" name="SubmitPledge" value="Submit my pledge">
</form>
<!--
<FORM METHOD="LINK" ACTION="<?php echo 'pledge3.php?'.htmlentities(session_name().'='.session_id()).'/'; ?>">
<INPUT TYPE="submit" VALUE="Submit my pledge">
</FORM>
-->
</body>
</html>
and here’s page 3 (pledge3.php):
<?php
ini_set('session.use_cookies',0);
session_id($_GET[htmlentities(session_name())]);
session_start();
?>
<html>
<body>
<?php
echo "session_id(): ".session_id();
echo "<br>SID: ".htmlspecialchars(SID);
echo "<p>"
?>
Thank you for your monthly pledge of: $
<?php
echo $_SESSION['amount'];
?>
<p>e-mail confirmation to user</p>
</body>
</html>
