Page 1 of 1

Maintaining state seems to be a problem - hmmmm???

Posted: Wed Jul 27, 2005 7:15 am
by benok
Hi everyone,

I have a signup.php file which contains a whole bunch of fields that users put details into when they are registering for my website. When the click the submit button, it goes to validate.php to validate all the fields are valid (i.e -> not empty etc etc).

So when the user clicks submit it goes to validate.php, I get all the variables from the first page by doing something like this.

$_SESSION['phpFirstName'] = $_POST['htmlFirstName'];
etc
etc

If there is an error, I want to go back to the signup.php page and notify the user of the offending fields on the form. Say the user didn't fill in the first name, I would return to the signup page like this:

header("location:http://address/signup.php?errors=firstname");

when I go back to the signup.php page, I expect that all other variables that passed validation have been "session"ized and that I can display them in the form without the user having to fill them in again - however the session variable doesn't seem to work and there is nothing in there when i return.

How can this be???

Posted: Wed Jul 27, 2005 7:43 am
by nielsene
Are you accepting the session cookie? or are you rejecting it?

Posted: Wed Jul 27, 2005 6:26 pm
by beno747
I don't know whether I'm accepting a session cookie or not.....how do I accept a session cookie???

Posted: Wed Jul 27, 2005 6:28 pm
by josh
Post code or we can't help

Remember you need session_start() on every page.

Posted: Wed Jul 27, 2005 6:37 pm
by beno747
Hi jshpro2,

Here is a snippet of signin.php

<form name="frmSignup" method="post" action="validate.php">
<input type="hidden" name="blnFirstTime" value="False">

<p><strong><font color="#CC00CC">Personal Details</font></strong></p>
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="24">Please enter a username</td>
<td><input type="text" name="txtboxUsername" value="<?php print($_SESSION['strUsername']) ?>"></td>
</tr>
<tr>
<td height="24">Please enter a password <font size="2"><em>(must be at least
6 characters long)</em></font></td>
<td><input type="password" name="textfield18"></td>
</tr>
<tr>
<td height="24">Retype your password</td>
<td><input type="password" name="textfield19"></td>
</tr>
<tr>
<td width="349" height="24">First Name</td>
<td width="356"><input type="text" name="txtboxFirstName" value="<?php print($_SESSION['strFirstName']) ?>"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="txtboxLastName" value="<?php print($_SESSION['strLastName']) ?>"></td>
</tr>
<tr>


In validate.php, I have

<?php
$errors = "";

if(empty($_POST['txtboxUsername']))
$errors = $errors . "username" . "+";
else
$_SESSION['strUsername'] = $_POST['txtboxUsername'];

and so on.......

down the bottom I have

if($errors <> "")
header("location:http://localhost:81/clubsuntory/signup.php?errors=" . $errors);

else
header("location:http://localhost:81/clubsuntory/signup.php");
?>


Thanks a lot for helping out.

Posted: Wed Jul 27, 2005 7:22 pm
by josh
You must put session_start() at the top of both pages for it to work.

Posted: Wed Jul 27, 2005 8:12 pm
by beno747
what about if I set session.auto_start = 1 in my php.ini file. Will I then have to call session_start() explicitly??


Thanks again mate