Jump to content

[SOLVED] protecting pages help


tqla

Recommended Posts

Hi. I have a survey that spans 3 pages. I want to make it impossible to go to page 2 and 3 by protecting them (ie: if someone goes to page 2 or 3 without going to page 1 first they will be sent to page 1.)

 

This sounds a lot like a user authentication system but it's not really. I don't require them to log in. They just need to start the survey from the beginning on page 1.

 

How do you do this? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/58798-solved-protecting-pages-help/
Share on other sites

On page one, you can have a hidden input type named "page1_complete", then on the second page, just check if that variable exists, if it doesn't....redirect them to page 1.

 

<?php

if (!isset($_POST['page1_complete'])){
    header('Location: page1.php');

} else {

//show page 2

}

?>

 

Then on page 2, have a hidden input called "page2_complete". And of course, on page 3 check if that variable exists, if it doesn't....redirect them to page 1 again.

 

 

 

Hi PocoBueno, I went a step further with your suggestion and created an auth.inc file like this:

<?php
session_start();
if (!isset($_SESSION["barcode"])) {
header('Location: index.php');
exit;
}
?>

 

 

Then I included this at the top of every protected page:

<?php
session_start();
include "auth.inc";
?>

 

Now users get sent to the index page if the variable 'barcode' is not set. 'barcode' is the first variable on the index page. So if they haven't visited the index page first they can't cut in to the other pages. yay!

 

I know this is old hat for most but I thought I'd put it up here on the chance that it may help someone else.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.