prime Posted October 8, 2007 Share Posted October 8, 2007 Sorry to bother the good people of this forum yet again but I have been working on a stylesheet switcher program, and I have added a cookie detection check to it <?php /* ------------------------------------------------------------------------------------------------------ */ /* --------------------------| CHECK IF BROWSER CAN SUPPORT COOKIES |------------------------------------ */ /* ------------------------------------------------------------------------------------------------------ */ if (isset($_COOKIE['cookiecheck'])){ $prevpage = $_COOKIE["prevpage"]; setcookie ("prevpage", "$prevpage", time(), "/", "duelindeals.com", "0"); setcookie ("cookiecheck", "$confirmed", time(), "/", "duelindeals.com", "0"); $prevpage = urldecode("$prevpage"); $prevpage = unserialize("$prevpage"); header("Location:$prevpage"); }elseif (empty($_COOKIE['cookiecheck']) AND ($_GET["check"] == "yes")){ echo "your browser does not support cookies, you must have cookies enabled to use this feature"; exit(); } /* ------------------------------------------------------------------------------------------------------ */ /* -------------------------------| INITIAL RECIEVING FILE |--------------------------------------------- */ /* ------------------------------------------------------------------------------------------------------ */ if (isset($_GET['stylesheet'])){ $stylesheet = $_GET['stylesheet']; $prevpage = $_SERVER['HTTP_REFERER']; $confirmed = "confirmed"; $prevpage = serialize("$prevpage"); $prevpage = urlencode("$prevpage"); setcookie ("cookiecheck", "$confirmed", time()+3000, "/", "duelindeals.com", "0"); setcookie ("prevpage", "$prevpage", time()+60, "/", "duelindeals.com", "0"); setcookie ("stylesheet", "$stylesheet", time()+9000, "/", "duelindeals.com", "0"); header("Location: $thisfile?check=yes"); }else{ header("Location:http://www.duelindeals.com"); } ?> Anyhow the script is working great except for one tiny little problem it's not referring back to the sending page after the script finishes proper execution, it's going back to the home page. what am i doing wrong, I tried echoing it out on the page to see what value $prevpage had and it seemed correct to the very page, but when its redirecting through the header it doesn't go there thx in advance Quote Link to comment https://forums.phpfreaks.com/topic/72242-solved-stylesheet-and-cookiecheck/ Share on other sites More sharing options...
sKunKbad Posted October 8, 2007 Share Posted October 8, 2007 It looks like you are setting your cookie to expire right when you make it. time() is right now. You might try something like time() + 10000. This may not be the only thing wrong with your script. Quote Link to comment https://forums.phpfreaks.com/topic/72242-solved-stylesheet-and-cookiecheck/#findComment-364283 Share on other sites More sharing options...
prime Posted October 8, 2007 Author Share Posted October 8, 2007 well the second part redirects to the frist part, similiar to form redux method and at that point those cookies are no longer needed, so I am setting those cookies to basicaly delete Quote Link to comment https://forums.phpfreaks.com/topic/72242-solved-stylesheet-and-cookiecheck/#findComment-364286 Share on other sites More sharing options...
prime Posted October 8, 2007 Author Share Posted October 8, 2007 the only problem is in the 1st step (the second block of code) I get the http_referrer and assign it to the $prev variable which i then serialize and url encode, then enter into a cookie the second step (first block of code) then retrieves that cookie, serializes and urldecodes and then assigns it to a variable then sets the cookie to delete and assigns that variable to the header for a redirect to the http referrer. the only problem is its not actually going to the http referrer just to the domain Quote Link to comment https://forums.phpfreaks.com/topic/72242-solved-stylesheet-and-cookiecheck/#findComment-364309 Share on other sites More sharing options...
prime Posted October 8, 2007 Author Share Posted October 8, 2007 Ok I found the problem thank you anyhow everyone for reference I was forgetting to place a simple exit in the first block of code right <?php /* ------------------------------------------------------------------------------------------------------ */ /* --------------------------| CHECK IF BROWSER CAN SUPPORT COOKIES |------------------------------------ */ /* ------------------------------------------------------------------------------------------------------ */ if (isset($_COOKIE['cookiecheck'])){ $prevpage = $_COOKIE["prevpage"]; setcookie ("prevpage", "$prevpage", time(), "/", "duelindeals.com", "0"); setcookie ("cookiecheck", "$confirmed", time(), "/", "duelindeals.com", "0"); $prevpage = urldecode("$prevpage"); $prevpage = unserialize("$prevpage"); header("Location:$prevpage"); exit(); // THIS IS WHERE i FORGOT THE EXIT }elseif (empty($_COOKIE['cookiecheck']) AND ($_GET["check"] == "yes")){ echo "your browser does not support cookies, you must have cookies enabled to use this feature"; exit(); } /* ------------------------------------------------------------------------------------------------------ */ /* -------------------------------| INITIAL RECIEVING FILE |--------------------------------------------- */ /* ------------------------------------------------------------------------------------------------------ */ if (isset($_GET['stylesheet'])){ $stylesheet = $_GET['stylesheet']; $prevpage = $_SERVER['HTTP_REFERER']; $confirmed = "confirmed"; $prevpage = serialize("$prevpage"); $prevpage = urlencode("$prevpage"); setcookie ("cookiecheck", "$confirmed", time()+3000, "/", "duelindeals.com", "0"); setcookie ("prevpage", "$prevpage", time()+60, "/", "duelindeals.com", "0"); setcookie ("stylesheet", "$stylesheet", time()+9000, "/", "duelindeals.com", "0"); header("Location: $thisfile?check=yes"); }else{ header("Location:http://www.duelindeals.com"); } ?> So now the script is working 100% thx for your help anyhow Quote Link to comment https://forums.phpfreaks.com/topic/72242-solved-stylesheet-and-cookiecheck/#findComment-364465 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.