Cookies

gesf

New member
hi.
I´m making a 'change skin' script for my site and i´m using php cookies.

This is the code i´m using to set the cookie:
// This cookie will expire after 30 days.
Code:
<?
 if (isset($skin))
  {
    setcookie ("skin","$skin",time()+60*60*24*30,"/",getenv("HTTP_HOST"));
  }
   
    $place = $_SERVER['HTTP_REFERER'];
    header ("Location: ".$place."");
?>

(1)
In the manual it´s written that:
If the cookie exists and i make a setcookie, the cookie will be updated with the new value...but somehow it doesn´t happen to me. It only works if i delete the cookie manually.
Any idea?
see if the skin script is working with you:
default version - Green version - Blue version

(2) (I.E case)
I´m using a free domain, not my host url.

By default, will be written on the cookie the host address.
...So that wont work with me! The address on the cookie is not the address on the browser.

e.g: set a cookie if u didn´t - now view with my domain

can i make the cookie to be accepted by the browser independently of the address on the address bar?

Regards,
gesf
 
gesf, check to make sure that getenv() is returning the value you expect. The HTTP_HOST variable is retrieved from the request header (e.g. not from the server), so it may be accurate. When I tested this right now, I found that getenv('HTTP_HOST') doesn't return anything, but that $_SERVER['HTTP_HOST'] does, so you might consider using the $_SERVER array instead. Or you might consider just hard-coding this at the top of your script or in a configuration script instead of grabbing it from the request.

One small nit-pick about your code: It's superfluous to put a single variable name between quotation marks, e.g. ...,"$skin",... -- it just makes PHP do extra processing. Instead, just use ...,$skin,...

By the way, I think your design is great. Let me know if you get this working so I can see the other skins.
 
Hey swirlee.
The cookie update is now working.

The cookie was not working because of that $skin variable.
It was the same as the cookie name and another one that i´m using in another code, to check the requested skin. That´s why it doesn´t work.
You can now see it working:
view default skin (1) - view skin 2 - view skin 3 - view skin 4

Ok, but now still the other question:
can i make the cookie to be accepted by the browser independently of the address on the address bar? Just to view the result with my domain

Regards,
gesf
 
You can make a cookie apply to an entire domain and its subdomains, but you can't make it apply to more than one domain. Check out the documentation for more information on this.
 
Back
Top