homepage Welcome to WebmasterWorld Guest from 54.196.197.153
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP Page B Only Accessible From Page A
Building on online competition with multiple pages
suga




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

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




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

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




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

ahhhh, i see. thank you!

willybfriendly




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

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




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved