session causing my form to clear..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
noob#10
Forum Newbie
Posts: 19
Joined: Wed Aug 15, 2007 9:55 am

session causing my form to clear..

Post 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!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post 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
User avatar
noob#10
Forum Newbie
Posts: 19
Joined: Wed Aug 15, 2007 9:55 am

Post by noob#10 »

i have a file which i require that already starts the session.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
noob#10
Forum Newbie
Posts: 19
Joined: Wed Aug 15, 2007 9:55 am

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: session causing my form to clear..

Post 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.
User avatar
noob#10
Forum Newbie
Posts: 19
Joined: Wed Aug 15, 2007 9:55 am

Post 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..
Post Reply