Jump to content

Redirection based upon session time out


ramone_johnny

Recommended Posts

Hey guys,

 

I have the following snippet of code that I'm *trying* to use in order to redirect users based upon a session time out. As I've relatively new to PHP and never written a redirect before, I just wanted to check that it's okay.

$_SESSION['start'] = isset($_REQUEST["start"]) ? $_REQUEST["start"] : "";
	
if (!isset($_SESSION['start'])) 
{
header('Location:http://localhost/advertise/placeanad.php');
session_destroy();
exit();
}

The page doesn't redirect, it just sits there - even upon refreshing it.

 

Is there something I'm missing?

 

Do I need to use an !empty statement or something?

Link to comment
https://forums.phpfreaks.com/topic/278192-redirection-based-upon-session-time-out/
Share on other sites

Sorry I just realised I was killing the session and then resetting it. My apologies. *doh!

 

I'm not quite sure where I set $_SESSION[''start'] to ''?

 

I'm debugging it to screen and it's showing 1 based upon the previous page.

 

<input type="hidden" name="start" value="1" id="start" />

$_SESSION['start'] = isset($_REQUEST["start"]) ? $_REQUEST["start"] : "";

This

 

$_SESSION['start'] will either had a value of $_REQUEST or a default "";

 

just use NULL as a default value

$_SESSION['start'] = isset($_REQUEST["start"]) ? $_REQUEST["start"] : null;

Well this might be a separate question, but I'm not sure I want null values for any of these request variables. Infact, I know I dont. Certainly not in the DB.

 

Is there a better way to write this?

$_SESSION['start'] = isset($_REQUEST["start"]) ? $_REQUEST["start"] : "";

Can I strip that stuff off the end and make sure isset($_REQUEST["start"]) actually holds a value?

What I mean is for the default value of $_SESSION['start'] not the $_REQUEST['start']

 

That code has nothing to do with the value of $_REQUEST['start']

 

We just replace the "" with NULL so that if (!isset($_SESSION['start']) will run if the the value of $_SESSION['start'] is null.

Using the "" as a default value of $_SESSION['start'], your if statement will never run becase !isset($_SESSION['start') is always FALSE

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.