Logic Flow

Hi,
I’m trying set up a web site so that every new visitor has to enter from the home page only, for this example I have used just 3 pages.

I have session_start(); at the top of each page.

The home page has a form at the bottom to enter the site, just a button no text its not a login page.

The next page is a contents list with a normal menu to each page.
I have used an include_once 'access.inc.php'; file in this page and the next page which is a list of products both are the same style.

The include file is

[code]<?php

/* view home page first */

if (isset($_POST[‘agree’])){
$set=$_POST[‘agree’];

$_SESSION[‘set’]=$set;
if(isset($_SESSION[‘set’])){

}
print $PHPSESSID;

}else{
header( ‘Location: http://www.plasticfolders.co.uk’ );
}

?>

[/code]
I have included the print session id just to prove a session is created.

If I try to load a page other than the home page the redirect works ok, I can enter the site from the home page.

The contents page loads but when I try to load the products page from the menu provided I’m sent back to home to start again.

I think I need test the session state before a new page loads.

Many thanks for any help or advice.

edintheclouds

You’ll have to start and check the session on every page you’re using. I’m thinking that’s what’s going wrong: somehow you’re checking a non-existant (or non-initialized) session.

I thought my include file did that, but maybe I need add more code.

Thanks Zyppora I’ll take another look at it.

I found the answer to the problem, if anyone else finds this script useful it’s listed below.

Cheers

[code]<?php

/* view home page first */

if (isset($_POST[‘agree’])){
$set=$_POST[‘agree’];
$_SESSION[‘set’]=$set;
}

if(isset($_SESSION[‘set’])) {

}

else {
header( ‘Location: http://www.yourdomain.co.uk’ );
}

?>

[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service