session problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

session problems

Post 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..
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
Post Reply