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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.