Page 1 of 1

Setting Cookies (remaining stateless)

Posted: Fri Aug 19, 2005 1:12 am
by $var
Hello,

I am learning about setting cookies, and I have this script that doesn't appear to be passing the cookie, i checked the cookies in the browser properties. Can anyone see why it isn't passing?

Code: Select all

<? 
	session_save_path("/.");
	session_start; 

       	if (!isset($id)) {
		srand((double)microtime()*1000000);
		$randval = rand();
		setcookie("id",$randval,time()+14400,"/","/.",0);
	} 

       $id = $HTTP_COOKIE_VARS["id"]
?>
Thanks


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Aug 19, 2005 1:55 am
by feyd
your domain isn't a valid value last I checked.

Posted: Fri Aug 19, 2005 6:08 am
by raghavan20

Code: Select all

setcookie("id",$randval,time()+14400,"/","/.",0);
the cookie does not have a value 8O
if you are unsure about using domain and paths, you can ignore those fields and use name, value and validity time alone. :)

Posted: Fri Aug 19, 2005 6:10 am
by shiznatix
i have never seen a /. used for a directory, if you want the current directory then its ./ not /.

Posted: Fri Aug 19, 2005 10:17 am
by $var
i have a real directory, i just put that to say the root,
i didn't post the full directory.. assume that /. is my full root.

Posted: Fri Aug 19, 2005 10:19 am
by $var
here's the full code...

<?
session_save_path("/home/.ufowasherkiln/meaghanb/meaghanbent.com/development/session");
session_start;

// set cookie if not already set
// syntax: setcookie(name, value, expiration, path, domain, security);
// we are calling the cookie "id", assigning it the value $randval, current time plus 14,400 sec/4 hr. valid for any page in the root
if (!isset($id)) {
srand((double)microtime()*1000000);
$randval = rand();
setcookie("id",$randval,time()+14400,"/","/home/.ufowasherkiln/meaghanb/meaghanbent.com/development",0);
}

?>


is it in the path of the domain that would most likely be causing the lack of cookie?

Posted: Fri Aug 19, 2005 10:57 am
by raghavan20
i dont think that you can have any unix or window directory name(cookie relative path) that starts with a period
http://www.december.com/unix/tutor/filenames.html
forgive me, if its beyond my knowledge

Posted: Fri Aug 19, 2005 11:15 am
by $var
i've tried so many combinations...

setcookie("id",$randval,time()+14400,"/"."meaghanbent.com",0);

setcookie("id",$randval,time()+14400,"./"."meaghanbent.com",0);

setcookie("id",$randval,time()+14400,"/"."/meaghanbent.com/development",0);

do any of these seem like they could work? the only reason i put the whole long path before was because when i was working with setting a session start path it needed the whole string to work.

Posted: Fri Aug 19, 2005 11:35 am
by raghavan20

Code: Select all

setcookie("id",$randval,time()+14400,"/"."meaghanbent.com",0); 

setcookie("id",$randval,time()+14400,"./"."meaghanbent.com",0); 

setcookie("id",$randval,time()+14400,"/"."/meaghanbent.com/development",0);
I see a dot operator instead of a comma before every domain path.

Posted: Fri Aug 19, 2005 12:23 pm
by $var
bingo

that was really stupid... i think that that was a post original post error...
thanks