Click here to get back home

Sessions under localhost

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Sessions under localhost pek 06-24-2008
Get Chitika Premium
Posted by pek on June 24, 2008, 11:28 am
Please log in for more thread options
OK, I've been having this problem for quite some time but never until
now I really needed a solution. I have never thought of a work around,
so I really need your help. Sorry if this has been mentioned already.
You can point me to the post and I'll gladly read. I googled this a
lot but, first, most people have tutorials for sharing sessions in
subdomains, and, second, I have no clue what keywords to use.

I am currently developing two web sites in my localhost. The first one
is http://localhost/pageone and the other http://localhost/pagetwo. I
have a login script for each. The login script can either be session
based (for temporary logins) or cookie based (for long term logins).

When I login in one site, I create two session variables named user
and key which store a user name and a random 128 characters string.
The key is stored in the database and changes upon each login (a
little security). After successfully logging in in pageone using
sessions, I noticed that in pagetwo I am also logged in. So I added a
session variable "domain" which I check on both pages to see if the
session information is for the right page. Although this works, I
found that now I can only be logged in in one page at a time. I am
assuming that sessions are shared.

Cookies can be set using the domain to avoid this. Is there anything
similar with sessions? Is there a work around? I'm also assuming that
this will not be the case if I buy a hosting and create different
domains for each web page. Is this true?

Thank you in advance.
Panagiotis.

Posted by =?ISO-8859-1?Q?=22=C1lvaro_G=2 on June 24, 2008, 11:42 am
Please log in for more thread options
pek escribió:
> OK, I've been having this problem for quite some time but never until
> now I really needed a solution. I have never thought of a work around,
> so I really need your help. Sorry if this has been mentioned already.
> You can point me to the post and I'll gladly read. I googled this a
> lot but, first, most people have tutorials for sharing sessions in
> subdomains, and, second, I have no clue what keywords to use.
>
> I am currently developing two web sites in my localhost. The first one
> is http://localhost/pageone and the other http://localhost/pagetwo. I
> have a login script for each. The login script can either be session
> based (for temporary logins) or cookie based (for long term logins).
>
> When I login in one site, I create two session variables named user
> and key which store a user name and a random 128 characters string.
> The key is stored in the database and changes upon each login (a
> little security). After successfully logging in in pageone using
> sessions, I noticed that in pagetwo I am also logged in. So I added a
> session variable "domain" which I check on both pages to see if the
> session information is for the right page. Although this works, I
> found that now I can only be logged in in one page at a time. I am
> assuming that sessions are shared.

Sessions are shared between all hosted sites unless you change it but it
shouldn't be an issue. Your problem is with cookies. It's pointless to
specify a *domain* in setcookie() because both sites are in the same
domain (localhost). What you need to specify is a *path*.

Same applies to session_set_cookie_params().


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--

Posted by pek on June 24, 2008, 12:25 pm
Please log in for more thread options
On Jun 24, 6:42=A0pm, "=C1lvaro G. Vicario"
> pek escribi=F3:
>
>
>
> > OK, I've been having this problem for quite some time but never until
> > now I really needed a solution. I have never thought of a work around,
> > so I really need your help. Sorry if this has been mentioned already.
> > You can point me to the post and I'll gladly read. I googled this a
> > lot but, first, most people have tutorials for sharing sessions in
> > subdomains, and, second, I have no clue what keywords to use.
>
> > I am currently developing two web sites in my localhost. The first one
> > ishttp://localhost/pageoneand the otherhttp://localhost/pagetwo. I
> > have a login script for each. The login script can either be session
> > based (for temporary logins) or cookie based (for long term logins).
>
> > When I login in one site, I create two session variables named user
> > and key which store a user name and a random 128 characters string.
> > The key is stored in the database and changes upon each login (a
> > little security). After successfully logging in in pageone using
> > sessions, I noticed that in pagetwo I am also logged in. So I added a
> > session variable "domain" which I check on both pages to see if the
> > session information is for the right page. Although this works, I
> > found that now I can only be logged in in one page at a time. I am
> > assuming that sessions are shared.
>
> Sessions are shared between all hosted sites unless you change it but it
> shouldn't be an issue. Your problem is with cookies. It's pointless to
> specify a *domain* in setcookie() because both sites are in the same
> domain (localhost). What you need to specify is a *path*.
>
> Same applies to session_set_cookie_params().
>
> --
> --http://alvaro.es- =C1lvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programaci=F3n web:http://bits.demogracia.com
> -- Mi web de humor al ba=F1o Mar=EDa:http://www.demogracia.com
> --

Uhm, sorry, indeed, I was already using path in setting the cookie, so
logging in with cookie works correctly. My problem is with sessions.
Because I want a user to be able to login for the current browsing
session. I now have a session_name before session_start with different
name and looks like it's working. I haven't really tested it a lot.

Posted by Jerry Stuckle on June 24, 2008, 3:07 pm
Please log in for more thread options
Álvaro G. Vicario wrote:
> pek escribió:
>> OK, I've been having this problem for quite some time but never until
>> now I really needed a solution. I have never thought of a work around,
>> so I really need your help. Sorry if this has been mentioned already.
>> You can point me to the post and I'll gladly read. I googled this a
>> lot but, first, most people have tutorials for sharing sessions in
>> subdomains, and, second, I have no clue what keywords to use.
>>
>> I am currently developing two web sites in my localhost. The first one
>> is http://localhost/pageone and the other http://localhost/pagetwo. I
>> have a login script for each. The login script can either be session
>> based (for temporary logins) or cookie based (for long term logins).
>>
>> When I login in one site, I create two session variables named user
>> and key which store a user name and a random 128 characters string.
>> The key is stored in the database and changes upon each login (a
>> little security). After successfully logging in in pageone using
>> sessions, I noticed that in pagetwo I am also logged in. So I added a
>> session variable "domain" which I check on both pages to see if the
>> session information is for the right page. Although this works, I
>> found that now I can only be logged in in one page at a time. I am
>> assuming that sessions are shared.
>
> Sessions are shared between all hosted sites unless you change it but it
> shouldn't be an issue. Your problem is with cookies. It's pointless to
> specify a *domain* in setcookie() because both sites are in the same
> domain (localhost). What you need to specify is a *path*.
>
> Same applies to session_set_cookie_params().
>
>

Incorrect. Cookies, which are used to manage sessions, are domain
specific. A browser will not send a cookie to another domain,
irregardless of the host.

In this case both are on "localhost", so the domain is the same.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================


Posted by =?ISO-8859-1?Q?Une_B=E9v?= =?I on June 25, 2008, 1:17 am
Please log in for more thread options

>
> In this case both are on "localhost", so the domain is the same.

I've found, from JavaScript, might be the same with PHP, that using
'localhost' works on some browser and not on other, but using
'127.0.0.1' works with all browsers available on Mac OS X.

Even some browser allows cookies when using 'file:///path/to/some.html'
but not all.

Is that right ?

--
Une Bévue

Similar ThreadsPosted
PHP Sessions doesn't work on my localhost August 10, 2005, 1:25 pm
localhost problem February 22, 2005, 6:10 pm
Cannot open localhost July 22, 2005, 10:20 pm
session_set_cookie_params on localhost May 23, 2006, 7:57 pm
php not working with 'localhost' July 2, 2007, 10:49 am
How to get the path from localhost? August 26, 2007, 12:53 pm
move_uploaded_file on localhost April 8, 2008, 4:21 pm
Find localhost’s IP number July 20, 2004, 10:53 pm
Why is localhost added to all my links ? January 22, 2005, 11:34 pm
Cannot connect to localhost using GoDaddy June 5, 2005, 5:46 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap