Page 1 of 1

session causing my form to clear..

Posted: Sat Aug 25, 2007 12:25 pm
by noob#10
elo guys!
i have a problem with my session, if a client would succesfully fill up the form he would be directed into a success page but if he try to use the back button in the browser the form will clear up (which is i think is correct) but if he accidentaly input a wrong value in a field, the session automatically clears all form. i have jscript that validates the form.

here is my session on the form:

Code: Select all

$secret = md5(uniqid(mt_rand(), true));
$_SESSION['secret'] = $secret;
$message =  (isset($_GET['error']) && $_GET['error'] != '') ? $_GET['error'] : '';

<input type="hidden" name="secret" value="<?php echo $secret; ?>" />
here is my session on the success form:

Code: Select all

if (!isset($_POST['secret']))
     
if (($_SESSION['secret'] != $_POST['secret']) || (!isset($_SESSION['secret'])))
{
   
    
}
else
{

}
is there somthing wrong with the session?? please i need help! thank you!

Posted: Sat Aug 25, 2007 12:33 pm
by califdon
I don't see a session_start() anywhere. You need that in every php script that relies on a session. Consult http://us.php.net/session_start

Posted: Sat Aug 25, 2007 12:35 pm
by noob#10
i have a file which i require that already starts the session.

Posted: Sat Aug 25, 2007 10:37 pm
by volka
please try

Code: Select all

echo '_POST: ', print_r($_POST, true), "<br />\n";
echo '_SESSION: ', print_r($_SESSION, true), "<br />\n";
if ( !isset($_POST['secret']) )
and post the output.

Posted: Sun Aug 26, 2007 5:03 am
by noob#10
sir where would i put the codes? should i put this on my success form or the form where the user inputs on the fields?

Re: session causing my form to clear..

Posted: Sun Aug 26, 2007 5:04 am
by volka
Short version: Where it fits.
Bit longer version: Your code contains
noob#10 wrote:if (!isset($_POST['secret']))
My code contains
volka wrote:if ( !isset($_POST['secret']) )
It should indicate where to put my code.

Posted: Tue Sep 04, 2007 10:02 am
by noob#10
sorry if it took me a while to reply on this..

i have this code on my function:

Code: Select all

$message = "Username Already Taken!";
header('Location: registration.php?error='.urlencode($message));
could this the one that causes my field to clear? what should i do?
is there any way i could post error message from a function without clearing the fields?? help me please..