so i am having a problem passing php session variables to multiple pages.
Essentially I have 1 form that collects answers. upon submission the user is taken to a page where dependent on the choice they made in the form, they will see a page loaded in an iframe. I have figured out how to make it work from form submission to the first page but when i try to carry over the variables to another page (via hyperlink) they do not stay.
below is my code:
form
<form method="post" action="offers.php">
0. <input type="text" name="name0"/> <br/><br/>
1. <input type="text" name="name1"/> <br/><br/>
<input type="submit" name="submit"/> </form>
Page 1 (after form submission offers.php)
<?php
session_start();
$_SESSION['name0'] = $_POST['name0'];
$_SESSION['name1'] = $_POST['name1'];
$name0 = $_POST['name0'];
$name1 = $_POST['name1'];
if ($name0 == 'dave')
$site="offer1.php";
elseif ($name0 == 'john')
$site="offer1a.php";
else
$site="http://websiteC.com";
?>
<HTML>
<body>
<div style="height:90px;">header</div>
<iframe src="<?php echo $site; ?>" name="offerFrame" style="width:100%; height:100%;" align="center"></iframe>
<br>
<a href="offer2.php">dfsdf</a>
</body>
</HTML>
page2 (user gets here via hyperlink – offer2.php)
<?php
session_start();
$_SESSION['name0'] = $_POST['name0'];
$_SESSION['name1'] = $_POST['name1'];
$name0 = $_POST['name0'];
$name1 = $_POST['name1'];
if ($name1 == 'dave')
$site="2a.php";
elseif ($name1 == 'john')
$site="2b.php";
else
$site="http://websiteC.com";
?>
<HTML>
<body>
<div style="height:90px;">header</div>
<iframe src="<?php echo $site; ?>" name="offerFrame" style="width:100%; height:100%;" align="center"></iframe>
<br>
<a href="offer3.php">dfsdf</a>
</body>
</HTML>
Thanks for the help
-dave
This is your problem in page 2:
The user gets there via a hyperlink, so the
$_POSTarray is empty and you are overwriting your session variables with empty ones.You can get the data via the session variables: