Page 1 of 1

Unable to set cookie

Posted: Fri Feb 10, 2006 5:40 pm
by kendall
Hey,

Sorry about this question but for some reason i think i need someone outside of the box to fill me in on this

i am trying to set a cookie using

Code: Select all

<?php
	$cookie = setcookie('ratings','set the cookie',time()+60*60*24*30,$PHP_SELF,$_SERVER['HTTP_HOST']);
	header("Location: administration/index.php");
	exit;
?>
and cont the index page i check to see if this cookie was set using

Code: Select all

if($_COOKIE['ratings'] || $HTTP_COOKIE_VARS['ratings'] || $_REQUEST['ratings'])
	print "cookie set";
else print "Could not set cookie";
echo $ratings;
but i get "could not set cookie" statement

I only have the above script setting the cookie so there are no output statements or blank lines
theres no pre-script process
im using an administrative profile on a windows XP
im using mozilla but it also doesnt work in IE
my register globals are on for a PHP 4.3.4

am i missing the point here?

Posted: Fri Feb 10, 2006 5:45 pm
by feyd

Code: Select all

$host = explode('.',$_SERVER['HTTP_HOST']);
if(count($host) > 2) {
  while(count($host) > 2) {
    array_shift($host);
  }
  $host = '.' . implode('.',$host);
} else {
  $host = implode('.',$host);
}
$cookie = setcookie('ratings','set the cookie',time() 60*60*24*30,'/',$host);
also, be aware that using a header redirection while setting a cookie may not set the cookie.

Unable to set cookie SOLVED

Posted: Fri Feb 10, 2006 6:00 pm
by kendall
oohhh :oops: