Forum Moderators: coopster

Message Too Old, No Replies

PHP Newbie question

$_POST and $_SESSION checking

         

le_gber

3:45 pm on Jul 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Riding on the PHP security / form highjacking thread : [webmasterworld.com...] , I was wondering if you PHP guys could give me an insight on how to do the following.

Let say I have a multi page contact form and want to continually check that the data is of the right 'kind'.

To give you an idea of what I mean:

1st page.
Enter name
Enter email
submit>>

2nd page
Enter income
Enter spouse name
submit>>

3rd page
review data entered and submit form.

I was thinking of using $_SESSIONS to pass data from one page to the other. The only thing is that between page 1 and 2 I check the form validity with $_POST['name'] and $_POST['email']. So between page 2 and 3 I cannot use the same function (as the data should be in $_SESSION otherwise it's going to be lost).

How would you go around this? Would you define a variable at the start of the function to assign any $_POST or $_SESSION value to it and then run the check on the variable instead of the $_POST['']?

something like

(isset($_POST['name']))? $name2check = $_POST['name'] : '';
(isset($_SESSION['name']))? $name2check = $_SESSION['name'] : '';

and further down

(isset($name2check))? run check on name : '';

Thanks

le_gber

[edited by: jatar_k at 5:44 pm (utc) on July 4, 2006]
[edit reason] fixed link [/edit]

eelixduppy

4:56 pm on Jul 4, 2006 (gmt 0)



Why don't you run the check on the value, and if it is clean set it to the session, and if not, return an error? Something like this maybe:

if(is_clean($_POST["email"])) { //is_clean is a custom function. it returns 1 if clean
$_SESSION["email"] = $_POST["email"];
}
else {
//return error
}

This is just an example ;)
Good luck!