Setting Cookies (remaining stateless)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Setting Cookies (remaining stateless)

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your domain isn't a valid value last I checked.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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. :)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

i have never seen a /. used for a directory, if you want the current directory then its ./ not /.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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?
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

bingo

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