I'm at my wits end on this one...
On my laptop, when I'm testing the code, everything works fine. However, when I move it to the server, it stops working...very frustrating. Here's the senario:
Laptop: Windows XP, IIS 5.1, php 5.0.3 build 2600
Server: Windows XP, Apache/1.3.23, php 4.1.1 build 2195
Page 1: Enter Info
After a person enters some mundane data, clicks submit, and the form is submitted. The data is validated, and is sent to page 2 for the confirmation.
Page 2: Confirmation
This displays what the user entered, and gives them the opportunity to change something. Once everything has been looked over and okayed, the user clicks 'Confirm', and page 2 will update the database, etc, and then refresh the page with a message stating that the info has been accepted. Then, the user clicks a link to take them back to page 1.
Here's the problem: Once the code is on the server, the session variables DO NOT get reset! Could it be a problem with the unset code? Could it be a PHP version problem? I have no idea...and ANY help is greatly appreciated!
Here's page 1:
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix
/* Initialize variables used in the page */
if (isset($_POST['name'])) {
$name = $_POST['name'];
}
else if (isset($_SESSION['name'])) {
$name = $_SESSION['name'];
}
else {
$name = NULL;
}
if (isset($_POST['id'])) {
$id = $_POST['id'];
}
else if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];
}
else {
$id = NULL;
}
if (isset($_POST['submit'])) {
$submit = $_POST['submit'];
}
else {
$submit = NULL;
}
// This is set for the first time into the page
$worked = NULL;
/* If the form is submitted, process the registration */
if (isset($submit)) {
//$worked = validate_page_1($id, $name);
$worked = true;
}
if ($worked) {
echo("inside worked");
// If the function worked, set sessions variables and go to next page
$_SESSION['name'] = $name;
$_SESSION['id'] = $id;
echo '
<FORM ACTION="page_2.php" METHOD="POST">
<P> Redirecting you...
<P> Please wait...
</FORM>
<script>
document.forms[0].submit();
</script>
';
}
else {
ECHO("HTTP SESSION VARS ");
print_r($HTTP_SESSION_VARS);
ECHO("<br><br>");
ECHO("SESSION VARS ");
print_r($_SESSION);
ECHO("<br><br>");
ECHO("POST VARS ");
print_r($_POST);
ECHO("<br><br>");
echo '
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td height="20">
</td>
</tr>
<tr>
<td align="center">
<H3>Page 1</H3>
</td>
</tr>
<tr>
<td align="center">
<form METHOD="POST" ACTION="'. $_SERVER['PHP_SELF'] .'">
<table>
<tr>
<td ALIGN="right" style="font-size:14px;line-height:15px;"><b>Name: </b></td>
<td><input NAME="name" SIZE="45" VALUE="' . $name . '"></td>
</tr>
<tr>
<td ALIGN="right" style="font-size:14px;line-height:15px;"><b>ID: </b></td>
<td><input NAME="id" SIZE="45" VALUE="' . $id . '"></td>
</tr>
</table>
<input TYPE="SUBMIT" VALUE="Next >>" name="submit"> <input TYPE="RESET" name="reset" VALUE=" Reset Page ">
</form>
</td>
</tr>
</table>
';
}
?>
and page 2:
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix
if (!isset($_SESSION['name'])) {
echo '
<FORM ACTION="page_1.php" METHOD="POST">
<P> Redirecting you back to the first page...
<P> Please wait...
</FORM>
<script>
document.forms[0].submit();
</script>
';
}
else {
/* Initialize variables used in the page */
if (isset($_POST['name'])) {
$name = $_POST['name'];
}
else if (isset($_SESSION['name'])) {
$name = $_SESSION['name'];
}
else {
$name = NULL;
}
if (isset($_POST['id'])) {
$id = $_POST['id'];
}
else if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];
}
else {
$id = NULL;
}
if (isset($_POST['submit'])) {
$submit = $_POST['submit'];
}
else {
$submit = NULL;
}
// This is set for the first time into the page
$worked = NULL;
/* If the form is submitted, process the registration */
if (isset($submit)) {
//$worked = confirm_page_2($id, $name);
$worked = true;
}
if ($worked) {
// unset all the location session variables
unset($_SESSION['id']);
unset($_SESSION['name']);
ECHO("HTTP SESSION VARS ");
print_r($HTTP_SESSION_VARS);
ECHO("<br><br>");
ECHO("SESSION VARS ");
print_r($_SESSION);
ECHO("<br><br>");
ECHO("POST VARS ");
print_r($_POST);
ECHO("<br><br>");
echo '
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td height="20">
</td>
</tr>
<tr>
<td align="center">
<H3>Page 2 - Confirmation</H3>
</td>
</tr>
<tr>
<td align="center">
<FONT COLOR="RED"><H3>Your information has been accepted!</H3></FONT>
<FORM ACTION="page_1.php" name="GOTOPAGE1" METHOD="POST">
<a href="#" onClick="ClickIT()">Enter Page 1 Information Again!</a>
</FORM>
<script>
function ClickIT() {
document.forms["GOTOPAGE1"].submit();
}
</script>
</td>
</tr>
</table>
';
}
else {
/* This sets up the table below the header */
echo '
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td height="20">
</td>
</tr>
<tr>
<td align="center">
<H3>Page 2 - Confirmation</H3>
</td>
</tr>
<tr>
<td align="center">
<form METHOD="POST" ACTION="'. $_SERVER['PHP_SELF'] .'">
<p><b>Please review and confirm the following information:</b></p>
<table>
<tr>
<td ALIGN="right" style="font-size:15px;line-height:15px;" width="200px" valign="top">
<b><i>Location Info</i>: </b>
</td>
<td style="font-size:14px;line-height:15px;" width="175px" valign="top">
<a href="page_1.php" >Click Here to Edit Data</a>
</td>
<td ALIGN="right" style="font-size:14px;line-height:15px;" width="150px" valign="top">
</td>
<td ALIGN="left" style="font-size:14px;line-height:15px;" width="150px" valign="top">
</td>
</tr>
<tr>
<td ALIGN="right" style="font-size:14px;line-height:15px;">
<b>Name: </b>
</td>
<td>
' . $name . '
</td>
<td ALIGN="right" style="font-size:14px;line-height:15px;" style="font-size:14px;line-height:15px;">
<b>ID:</b>
</td>
<td ALIGN="left">
' . $id . '
</td>
</tr>
</table>
<input TYPE="SUBMIT" VALUE="Confirm Data!" name="submit">
</form>
</td>
</tr>
</table>
';
}
}
?>
Works great in test, but as soon as it gets moved to the server, the unset for the session variables fail...
Thanks in advance for the help!
-J