Jump to content

Session Cookie


phpretard

Recommended Posts

I have people registering on my site and for what ever reason they leave there computer after registration and this conflicts with some other reporting sofware I am using.

 

I need to set a cookie and give them X amount of time with $_SESSION['PoolID']; Set.

 

I then would like to redirect them to somewhere else (off of my site).

 

My problem is seting the cookie.  I can set the seeion of course but setting the session and settin it as a cookie troubles me?

 


<?php

session_start();  

$_SESSION['PoolID']="Stuff"; 

if (!isset($_COOKIE['session'])) {   
session_destroy();   // if not, destroy session
header ('Location: http://www.google.com');   
exit;     
}

if (!empty($_SESSION['PoolID'])) {   
setcookie('session', 'active', time()+3600);   
} else {
header ('Location: http://www.google.com');   
exit;   // exit the current script
}

?>

 

Everytime I open my test page it just send me to google...

 

Can someone help me here?

Link to comment
Share on other sites

<?php session_start();  

$_SESSION['PoolID']="Stuff"; 

// THERE SHOULD BE SOME CONDITION HERE <<<< IT MISSING SURLEY...........

//LIKE YOU BEEN TOLD YOUR GOTO GOOGLE REGARDLESS,  UNLESS YOU ADD ANOTHER CONDITION

if (!isset($_COOKIE['session'])) {   
session_destroy();   // if not, destroy session
header ('Location: http://www.google.com');   
exit;     
}

if (!empty($_SESSION['PoolID'])) {   
setcookie('session', 'active', time()+3600);   
} else {
header ('Location: http://www.google.com');   
exit;   // exit the current script
}

?>

Link to comment
Share on other sites

I see what you mean...

 

<?php 
session_start();  

$_SESSION['PoolID']="Stuff"; 





if (!empty($_SESSION['PoolID'])) {   
setcookie('session', 'active', time()+20);   
} else {
header ('Location: http://www.google.com');   
exit;   // exit the current script
}



if (!isset($_COOKIE['session'])) {   
session_destroy();   // if not, destroy session
header ('Location: http://www.google.com');   
exit;     
}

echo "<pre>". print_r($_SESSION,true) ."</pre>";

?>

 

So how do check for the cookie on the same page?

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.