Is there any way to prevent access to a page without viewing the home page?

QuwenQ

Member
Messages
960
Reaction score
0
Points
16
Is there any way to prevent going to a page, unless the viewer has visited the front page?

So that if they try to access any page without viewing the front page they are automatically redirected to the main page?

I'd be willing to add a code to every single page.
 

flinx

New Member
Messages
68
Reaction score
0
Points
0
You might use sessions.

On top of the main page

PHP:
<?php
session_start();
$_SESSION['main'] = 1;
?>

On top of all the other pages

PHP:
<?php
session_start();
if (!isset($_SESSION['main'])) {
   header("http://www.sitename.com/index.php");
   exit();
}
?>

Make sure to put this code before everything else in the script.

Read more about headers here.
Read more about sessions here.
 
Last edited:
Top