Page 1 of 1

session problems

Posted: Wed Nov 07, 2007 10:17 am
by SirChick
I have a session issue with my scripts... i put sessions on pages like this:

Code: Select all

$_SESSION['referer'] = $_SERVER['SCRIPT_NAME'];
this is in estateagents.php


stop people clicking urls like /process.php

which would cause the process to run when accessed so i decided to put this in my process page :

Code: Select all

if (isset($_POST['SellHouse']) && $_SESSION['referer'] == 'estateagents.php'){
do code}else{
header("location: estateagents.php");
}

but it is not working .. it just headers every time rather than doing the code..

Posted: Wed Nov 07, 2007 10:41 am
by CoderGoblin
You don't tell us what you think your problem is. Are you sure it is the session ?
First thing to do is check the values of $_POST['SellHouse'] and $_SESSION['referer'] (print_r them out for debugging purposes) and let us know what you get.

As a point of interest

Code: Select all

header("location: http://www.yoursite.com/estateagents.php");
should immediately be followed by

Code: Select all

exit;
Without the exit, redirection will not happen until code is stopped either by an exit/die etc or when the rest of the code is completed. This means anything after your if statement will be processed.