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
https://forums.phpfreaks.com/topic/126273-session-cookie/
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
https://forums.phpfreaks.com/topic/126273-session-cookie/#findComment-653035
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
https://forums.phpfreaks.com/topic/126273-session-cookie/#findComment-653410
Share on other sites

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.