Welcome to WebmasterWorld Guest from 50.19.34.234

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Page B Only Accessible From Page A

Building on online competition with multiple pages

     

suga

6:54 pm on Mar 12, 2009 (gmt 0)

5+ Year Member



I'm posting this question on webmasterworld because I just can't figure out how to search for it online! I'm building on online sweepstakes/competition with about 3 different pages: step1.php, step2.php, step3.php. The contestant should only be able to get to step3.php after completing step1.php and step2.php because step3.php is where they actually enter their personal info into our database. So how do I ensure that the user takes the steps in the correct order before getting to step3?

Thanks.

rocknbil

7:27 pm on Mar 12, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Do this all in one script.


if (
(isset($_POST['some_var_from_step_1'])) and
(isset($_POST['some_var_from_step_2']))
) {
// Output step 3.
// Of course, don't use $_POST directly, cleanse your data
}
else if (isset($_POST['some_var_from_step_1'])) {
// Output step 2, store a var from step 1 as a hidden
// or session variable.
}
else {
// output step 1
}

suga

8:29 pm on Mar 12, 2009 (gmt 0)

5+ Year Member



ahhhh, i see. thank you!

willybfriendly

9:08 pm on Mar 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Session variables might be better, lest someone submit phonied up post data.

if(!isset($_SESSION[stage]);
$_SESSION[stage] = 0;
else
$_SESSION[stage] = $_SESSION[stage]++;

function stage1()
{
/* relevant coding */
}
function stage2()
{
/* relevant coding */
}
/* Etc. ...*/
function defaultDisplay()
{
/* relevant coding */
}
$stage = (int)$_SESSION[stage];

switch($stage)
{
case 1:
stage1();
break;
case 2:
stage2();
break;
/* Continue as needed */
default:
defaultDisplay();
}

I find that the switch statement is more intuitive when going back months (or years) later. Far easier than trying to decipher a long string of if/else statements.

suga

9:44 pm on Mar 12, 2009 (gmt 0)

5+ Year Member



thank you also, i think i like the use of session variables better as well.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month