cookies, on a sub domain?

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
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

cookies, on a sub domain?

Post by Ne0 »

Hi everyone. Im using an invision forum on my website, and i want to make it so when your logged in on the forum, your logged in on the website. Ive made it so my registration and everything uses the same table/database, and ive got all that, what my problem is invision used cookies to store login info. So i did some searching and pulled up the cookie that stores the info, and made this:

Code: Select all

<?php
if (isset($_COOKIE['member_id'])) {
	$infotemp = explode("-",$_COOKI['member_id']);
	$userid = $infotemp[0];
	echo "HEY $userid";
} else {
	echo "NOT SET!";
}
?>
it didnt reconize that the cookie was set, so i scratched my head for a few seconds, and realized that the cookie was set for forums.mydomain.com, not mydomain.com, wich is were the site is. Is there anyway to get around this? Am I wrong and this is not the problem?

Thanks in advanced.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

not looking at your logic, but correct the syntax error

$_COOKIE, not $_COOKI

also, make sure the path in the setcookie is set to all subdomains.

go to php.net and search for setcookie() for more info
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

straight from the manual
To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to http://www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the spec for details.
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

Ok, thank you, i know now that the cookie isnt being set for all domains. I found out that they are setting the cookie through Javascript, i modifed it to this:

Code: Select all

document.cookie = ipb_var_cookieid + name + "=" + value + "; expire=" + expire + "; domain=.ne0.fgvhost.net;"
then, i did a simple test to see if that worked. It sais "NOT SET!", i moved the file that im working on into the forums subdomain, ran it, and it printed "HEY" and the value of the cookie.

i made some progress...but now im stuck. how can i get it to set the cookie for all domains?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

make sure to set the path to /
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

nothings working. i tried:

Code: Select all

document.cookie = ipb_var_cookieid + name + "=" + value + "; expire=" + expire + "; domain='.ne0.fgvhost.net'; path='/';";
and

Code: Select all

document.cookie = ipb_var_cookieid + name + "=" + value + "; expire=" + expire + "; domain=ne0.fgvhost.net; path=/;"
i dont know whats wrong
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's wrong with using [php_man]setcookie[/php_man]()?
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

i dont know? ask the people who wrote ipb 2.0, im just trying to get it so when your logged in on the forum your logged in on the site and vis versa. i dont want to mess with things to badly, because im afraid i might mess something up. i guess i will try using setcookie() now, but im going to have to modify alot of things
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

i guess u could just use setcookie() from php, since later on i do not think that the script will make any destinct wether the cookie has been set with java or php ...
Post Reply