I am trying to collect some user information which I will then use to log him/her in. I have a file called login.php which collects the information and which calls session_start() right at the top, this works the first time through (I can actually see a session ID). Once in the login.php, the user enters his name, last name, email and language. When this form is submitted, it forwards to registration.php where these values are retrieved and placed into cookies.
The problem I am having is that these variables are blank by the time I get to registration.php.
My questions are,
(1) Do I have to do session_start() at the top of each of these files or simply login.php ?
(2) Can you advise me on what I may be doing wrong ? thanks.
I am using Internet Explorer 6 as well as apache and the latest PHP.
Below please find the source code.
LOGIN.PHP
<?php
session_start();
// Works if session cookie was accepted
// echo '<br /><a href="page2.php">page 2</a>';
// Or maybe pass along the session id, if needed
echo '<br /><a href="login.php?' . SID . '">page 2</a>';
?>
<html>
<head>
<title>
Registration - Caripito.com
</title>
<?php
include 'js.php';
?>
<link href="Assets/master.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<?php
include 'header.php';
?>
</tr>
<tr>
<td>
<?php
include 'menubar.php';
?>
</td>
</tr>
</table>
<table width="607" border="0">
<tr>
<td> </td>
</tr>
<tr>
<td width="601"> <form method="post" action="registration.php">
<table width="387">
<tr>
<td width="72"><strong><font color="#0000FF" face="Arial, Helvetica, sans-serif">
First Name </font></strong></td>
<td width="168"> <strong><font color="#0000FF" face="Arial, Helvetica, sans-serif">
<input type="text" name="fname" maxlength=\"10\">
</font></strong></td>
</tr>
<tr>
<td><strong><font color="#0000FF" face="Arial, Helvetica, sans-serif">
Last Name </font></strong></td>
<td> <strong><font color="#0000FF" face="Arial, Helvetica, sans-serif">
<input type="text" name="lname" maxlength=\"10\">
</font></strong></td>
</tr>
<tr>
<td><strong><font color="#0000FF" face="Arial, Helvetica, sans-serif">
Email </font></strong></td>
<td> <strong><font color="#0000FF" face="Arial, Helvetica, sans-serif">
<input type="text" name="email" maxlength=\"20\">
</font></strong></td>
</tr>
<tr>
<td><strong><font color="#0000FF" face="Arial, Helvetica, sans-serif">
Idioma </font></strong></td>
<td> <strong><font color="#0000FF" face="Arial, Helvetica, sans-serif">
<input type=radio name="idioma" value="spanish" checked>
Español
<input type=radio name="idioma" value="english">
Inglés </font></strong></td>
</tr>
<tr>
<td colspan="2"><div align="center"><font face="Arial, Helvetica, sans-serif">
<input type="submit" name="submit" value="Submit">
</font></div></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td><p><font color="#0000FF" face="Arial, Helvetica, sans-serif"><strong>Su
navegador debe aceptar "Cookies" para que el registro pueda
funcionar.</strong></font></p>
<p><font color="#0000FF" face="Arial, Helvetica, sans-serif"><em><strong>Your
browser must accept Cookies in order for this to work.</strong></em></font></p></td>
</tr>
</table>
</font>
</body>
</html>
REGISTRATION.PHP
<?
setcookie("fname",$HTTP_POST_VARS['fname'],time() 3600);
setcookie("lname",$HTTP_POST_VARS['lname'],time() 3600);
setcookie("usuario",$HTTP_POST_VARS['fname'] . " " . $HTTP_POST_VARS['lname'],time() 3600);
setcookie("idioma",$HTTP_POST_VARS['idioma'], time() 3600);
?>
<html>
<head>
<title>
Registration
</title>
<?php
include 'js.php';
?>
<link href="Assets/master.css" rel="stylesheet" type="text/css">
<meta http-equiv="refresh" content="5; URL=index.php?">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/btnCustomerService_on.jpg','images/btnLocations_on.jpg')">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<?php
include 'header.php';
?>
</tr>
<tr>
<td>
<?php
include 'menubar.php';
?>
</td>
</tr>
</table>
<?
if ($_COOKIE["idioma"] == "english")
{
echo "<h1>Registration</h1>";
}
else
{
echo "<h1>Registro</h1>";
}
?>
<font size=+2 face = verdana>
</font>
<?
if ($COOKIE["idioma"] == "english")
{
echo "Dear " . $COOKIE["fname"] . " " . $COOKIE["lname"] . ",<br><br>" . "We have received your registration request.<br>";
}
else
{
echo "Estimado " . $COOKIE["fname"] . " " . $_COOKIE["lname"] . ",<br><br>" . "Hemos recibido tu registro.<br>";
}
?>
<center><a href="index.php">Home</a></center>
</body>
</html>