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?

Edited by ramone_johnny
Link to comment
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" />

Link to comment
Share on other sites

$_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;
Edited by Eiseth
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Edited by Eiseth
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.