473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Sessions under localhost

pek
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.
Jun 27 '08 #1
7 2371
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
--
Jun 27 '08 #2
pek
On Jun 24, 6:42*pm, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
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
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- Á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
--
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.
Jun 27 '08 #3
Á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.
js*******@attglobal.net
==================

Jun 27 '08 #4
pek wrote:
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.
Your problem is the domain is the same for both - so the browser will
send the session cookie to either one. This will not occur on a "live"
site.

I'm assuming these will be two different sites when you upload them -
i.e. www.example.org and www.example.com.

If this is the case, you have another problem - you probably won't use
www.example1.com/page1 and www.example.com/page2 when you upload them.
So, set up your web host to handle two different sites, and change your
HOSTS file to reflect the two sites. You can find more information on
how to do this in alt.apache.configuration (assuming, of course, this is
an Apache server).

Then you will be duplicating the "live" environment - and possibly find
some bugs (i.e. with file paths) that you didn't know about before.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #5
pek
On Jun 24, 10:11*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
pek wrote:
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.
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.

Your problem is the domain is the same for both - so the browser will
send the session cookie to either one. *This will not occur on a "live"
site.

I'm assuming these will be two different sites when you upload them -
i.e.www.example.organdwww.example.com.

If this is the case, you have another problem - you probably won't usewww..example1.com/page1andwww.example.com/page2when you upload them.
I didn't quite get what did you meant with "you probably won't use
www.example.com/page1 and www.example.com/page2
I will be upload the two sites in the same hosting but the domains
will be different (i.e. www.page1.com and www.page2.com)..
Currently, using session_name("page1") and session_name("page2") works
correctly. I'm not sure if this is how it should be..
So, set up your web host to handle two different sites, and change your
HOSTS file to reflect the two sites. *You can find more information on
how to do this in alt.apache.configuration (assuming, of course, this is
an Apache server).

Then you will be duplicating the "live" environment - and possibly find
some bugs (i.e. with file paths) that you didn't know about before.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Jun 27 '08 #6
Jerry Stuckle <js*******@attglobal.netwrote:
>
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
Jun 27 '08 #7
These are not PHP questions, but I'll answer them. However, you need to
find a more appropriate newsgroup for your questions. This one is for
discussing how to program in PHP, not javascript or browsers.

Une Bévue wrote:
Jerry Stuckle <js*******@attglobal.netwrote:
>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.
This has nothing to do with either browsers or PHP - it's strictly a
TCP/IP function. Correctly set up, the system will know that
'localhost' indicates the loopback interface, 127.0.0.1.

And remember that Javascript runs on the client - so if you refer to
'localhost', you are referring to the client's system - not the server!

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

Is that right ?
file: goes directly to the file system and not through the web server.
You're not using HTTP, so cookies are not involved.

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

Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Mateer | last post by:
Hi Why does the following code allow me to keep the same session when in the same sub domain (ie admin.localhost), yet not when I goto another related domain eg main.localhost? I would like...
8
by: Steve Fitzgerald | last post by:
The below login script does work. The form does not seem to be submitting. I keep getting the username and password fields. The only errors I get are notices that email and password and undefined...
3
by: Simon K | last post by:
Hi I am working with sessions to check if the user is logged in. This usually works fine and all my .asp-pages checks if: <% session.Contents("loggedIn")=True %> But this only works on my...
5
by: Mark | last post by:
Hi, I want to run in my .Net Windows Form this statement System.Diagnostics.Process.Start(strURLCommand) to open the browser and navigate to the specified URL. The URL is an ASP.Net Web...
5
by: Rob | last post by:
I have an ASP.NET application that uses forms-based authentication. A user wishes to be able to run multiple sessions of this application simultaneously from the user's client machine. The...
0
by: Jerad Rose | last post by:
I have an odd scenario. I am working on a hybrid site that uses various development platforms, namely traditional ASP and Lasso (a Mac scripting language). The site uses its own custom sessions...
1
by: Duncan | last post by:
I have a strange problem with sessions in PHP 5. I have a simple script that prints a random number both as a string and a picture on the screen. When I run the script for the first time, it works...
2
by: vmalhotra | last post by:
Hi I am new in python scripting. I want to open a Multiple telnet session through once script. In other way i can tell i want to open two linux consoles through one script. I wrote one...
7
by: Nico | last post by:
Dear all, I made the following form. <FORM METHOD="POST" ACTION="prova.php"> <b>Combination</b><br><br> Element 1: <INPUT NAME="el1" TYPE="TEXT"> <BR> Element 2: <INPUT NAME="el2"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.