RE: [PHP] Followup to session question / scope of session
| From: | Chad Day | Date: | Fri, 19 Jul 2002 18:59:57 +0000 |
| Subject: | RE: [PHP] Followup to session question / scope of session | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108561@lists.php.net to get a copy of this message | ||
Right.. I understand that other virtual domains can't read the cookie. The
problem is I can't control what domain session_start() sets the cookie in..
it appears to set it on the exact domain I am at.
I noticed if I do this:
http://online-leagues.com/leagues/testdir/loginme.php
(no www)
the next page (without www) works ok. returns valid.
If I then add a www in front of that link, it ALSO returns valid.
so perhaps session_start(), since I am starting at online-leagues.com (not
www.online-leagues.com) sets a cookie that is valid for all of
*.online-leagues.com? This appears to be the case, as I just tried
sticking mail.online-leagues.com in that 2nd script (the one with the
check), and it returns valid also.
So.. I guess the solution is to set the cookie at online-leagues.com, not
www.online-leagues.com, and this will make it readable by all of
*.online-leagues.com.
Hopefully, this helps someone else out there somewhere. :) Thanks to
everyone for helping me figure this out (at least, I hope this is figured
out!)
Thanks again,
Chad
-----Original Message-----
From: Erik Price [mailto:erikprice@mac.com]
Sent: Friday, July 19, 2002 3:04 PM
To: Chad Day
Cc: php-general@lists.php.net
Subject: Re: [PHP] Followup to session question / scope of session
On Friday, July 19, 2002, at 02:40 PM, Chad Day wrote:
> If I refer to a script without the filename
> (http://www.online-leagues.com/my), Apache apparently interprets that as
> (http://online-leagues.com/my/look-for-the-index-file).
This depends on your Apache configuration, and is pretty normal.
Usually it will look for index.html first, then index.php, then
index.shtml, or whatever order is specified in your httpd.conf file.
You may be able to override this with a .htaccess file too.
> Now, I could just rewrite all the URLs, but in the near future I want
> to be
> able to have http://my.online-leagues.com and
> http://calendar.online-leagues.com working and use data in
> those
> sessions.
>
> I'm not sure what cookies have to do with this, aside from passing
> along the
> session id.
That's exactly what cookies have to do with this. By relying on the
cookie to pass the session id, you can only maintain the session by
making this cookie available to the server. Since a cookie is only
readable by the domain which sets the cookie, you need to adjust the
value of the "domain" attribute of the cookie so that it is readable by
other subdomains. The easiest way to do that is to set the cookie's
domain attribute to ".domain.com" which means "any subdomain of
domain.com". Refer to this spec, it will help you understand:
http://wp.netscape.com/newsref/std/cookie_spec.html
Note I just found a quick article, which I haven't read, which may help
you:
http://www.phpbuilder.com/columns/chriskings20001128.php3
> <?
> session_start();
>
> $I_AM_A_NEW_VALID_USER = '1';
> session_register("I_AM_A_NEW_VALID_USER");
>
> echo "<a
> href=\"http://online-leagues.com/leagues/testdir/index.php?";
> echo $PHPSESSID;
> echo "\">link</a>";
> ?>
What is the URL of this link? Look at it closely, it is missing
something:
<a href="http://online-
leagues.com/leagues/testdir/index.php?XXXXXXX">link</a>
You've specificed a GET variable name but no value. Try doing that
again, but put the name "SID=" immediately before the $PHPSESSID value.
> I apologize if I am missing something basic here / am not
> understanding.. I
> just don't know what I have to do to get my session to work across that
> entire domain.. I thought worst case, passing along the SID would work,
> but
> that doesn't seem to be working either.
>
No big deal it just looks like you forgot to name the GET variable.
Read up on that cookie stuff, it'll help you in the long run if you're
serious about doing a lot of session work.
Erik
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php