phpretard Posted September 29, 2008 Share Posted September 29, 2008 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? Quote Link to comment Share on other sites More sharing options...
timmah1 Posted September 29, 2008 Share Posted September 29, 2008 Just a thought, but wouldn't you get sent to google regardless if the cookie is set or not? Quote Link to comment Share on other sites More sharing options...
phpretard Posted September 29, 2008 Author Share Posted September 29, 2008 I am... any suggestion? Quote Link to comment Share on other sites More sharing options...
mat-tastic Posted September 29, 2008 Share Posted September 29, 2008 To be honest, unless I am being thick, I am not quite getting what you want. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 29, 2008 Share Posted September 29, 2008 <?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 } ?> Quote Link to comment Share on other sites More sharing options...
phpretard Posted September 29, 2008 Author Share Posted September 29, 2008 // THERE SHOULD BE SOME CONDITION HERE <<<< IT MISSING SURLEY........... //LIKE YOU BEEN TOLD YOUR GOTO GOOGLE REGARDLESS, UNLESS YOU ADD ANOTHER CONDITION This is the part I need help with. Quote Link to comment Share on other sites More sharing options...
phpretard Posted September 29, 2008 Author Share Posted September 29, 2008 I just do not want people sitting Idle on my site (logged in) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 29, 2008 Share Posted September 29, 2008 You're checking for the cookie before you set it, so obviously the won't have it set. Switch the order. Also, $_SESSION['pool_id'] is set regardless, so it'll always set the cookie then. You really need to be more specific. Quote Link to comment Share on other sites More sharing options...
phpretard Posted September 29, 2008 Author Share Posted September 29, 2008 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.