Jump to content

[SOLVED] cookies and headers


prime

Recommended Posts

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

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");
}
?>

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

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 :-)

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.