prime Posted October 7, 2007 Share Posted October 7, 2007 I seem to be having a slight problem I have the following code <?php $stylesheet = $_GET['stylesheet']; if (!empty($stylesheet)) { setcookie ("stylesheet", "$stylesheet", "time()+9000", "/", "duelindeals.com", "0"); header("Location: $HTTP_REFERER"); } else { header("Location:http://www.duelindeals.com"); } ?> I am using a simply transmitting the data via url which I know is transmitting correctly here's the two links I am using to access this page <div class="sitenavigation"> <span class="menuheads">Site Styles</span><br /> <ol> <li><a href="http://<?php echo "$siteserv"; ?>/switcher.php?stylesheet=default">Default</a></li> <li><a href="http://<?php echo "$siteserv"; ?>/switcher.php?stylesheet=easyreading">Easy Reading</a></li> </ol></div> anyhow the problem is once I click on the links, the data transmits to the switcher.php script like it should be but the cookie is not being set nor is the page redirecting properly. I had this working exellent on php4 but once I upgraded to php5 I am getting the following errors: Warning: setcookie() expects parameter 3 to be long, string given in /home/content/p/r/i/primefalcon/html/switcher.php on line 6 Warning: Cannot modify header information - headers already sent by (output started at /home/content/p/r/i/primefalcon/html/switcher.php:6) in /home/content/p/r/i/primefalcon/html/switcher.php on line 7 Link to comment https://forums.phpfreaks.com/topic/72158-solved-cookies-and-headers/ Share on other sites More sharing options...
sKunKbad Posted October 7, 2007 Share Posted October 7, 2007 Try: <?php if (isset($_GET['stylesheet']){ $stylesheet = $_GET['stylesheet']; setcookie ("stylesheet", "$stylesheet", time()+9000, "/", "duelindeals.com", 0); header("Location: $HTTP_REFERER"); }else{ header("Location:http://www.duelindeals.com"); } ?> Link to comment https://forums.phpfreaks.com/topic/72158-solved-cookies-and-headers/#findComment-363836 Share on other sites More sharing options...
prime Posted October 7, 2007 Author Share Posted October 7, 2007 Parse error: syntax error, unexpected '{' in /home/content/p/r/i/primefalcon/html/switcher.php on line 2 Link to comment https://forums.phpfreaks.com/topic/72158-solved-cookies-and-headers/#findComment-363838 Share on other sites More sharing options...
d.shankar Posted October 7, 2007 Share Posted October 7, 2007 skunk you are correct though that code has some error. Here it is <?php if (isset($_GET['stylesheet'])){ $stylesheet = $_GET['stylesheet']; setcookie ("stylesheet", "$stylesheet", time()+9000, "/", "duelindeals.com", 0); header("Location: $HTTP_REFERER"); }else{ header("Location:http://www.duelindeals.com"); } ?> Credits to skunk Link to comment https://forums.phpfreaks.com/topic/72158-solved-cookies-and-headers/#findComment-363839 Share on other sites More sharing options...
prime Posted October 7, 2007 Author Share Posted October 7, 2007 Ok the cookies setting great but it's not redirecting back to the page that it came from, just showing a black page Link to comment https://forums.phpfreaks.com/topic/72158-solved-cookies-and-headers/#findComment-363841 Share on other sites More sharing options...
d.shankar Posted October 7, 2007 Share Posted October 7, 2007 It did and it redirected me to the homepage. Link to comment https://forums.phpfreaks.com/topic/72158-solved-cookies-and-headers/#findComment-363845 Share on other sites More sharing options...
prime Posted October 7, 2007 Author Share Posted October 7, 2007 actualy there was an error stopping it going back which I have now fixed header("Location: $HTTP_REFERER"); I modified the code to <?php if (isset($_GET["stylesheet"])){ $stylesheet = $_GET["stylesheet"]; $page = $_SERVER['HTTP_REFERER']; setcookie ("stylesheet", "$stylesheet", time()+9000, "/", "duelindeals.com", "0"); header("Location: $page"); }else{ header("Location:http://www.duelindeals.com"); } ?> thx for your help :-) Link to comment https://forums.phpfreaks.com/topic/72158-solved-cookies-and-headers/#findComment-363857 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.