473,396 Members | 1,933 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,396 software developers and data experts.

php session without cookie useage

hi all

i need some clarification on how the php session work in relation to
cookies.

we have a web site where users need to log in. a few of our users were
having troubles with their browser clients having different levels of
cookie security settings. i assumed a solution would be to have the php
site use the session only, and set session.use_cookies to 0 in the
php.ini file. after doing this, the session no longer persits after
moving from page to page.

does the session need to have cookies enabled to work? if so, what is
the point of this setting? if not, what settings do i need to set to
make the session work sever side only?

thanks in advance

Aug 11 '05 #1
7 14504
In article <11*********************@f14g2000cwb.googlegroups. com>,
eh*******@gmail.com wrote:
hi all

i need some clarification on how the php session work in relation to
cookies.

we have a web site where users need to log in. a few of our users were
having troubles with their browser clients having different levels of
cookie security settings. i assumed a solution would be to have the php
site use the session only, and set session.use_cookies to 0 in the
php.ini file. after doing this, the session no longer persits after
moving from page to page.

does the session need to have cookies enabled to work? if so, what is
the point of this setting? if not, what settings do i need to set to
make the session work sever side only?

thanks in advance


Since web servers don't retain state from page to page, it is up to the
browser or the application to maintain the state if needed. Browsers
can do so with a cookie. Alternatively, if you code the application to
transfer a session key created on login to subsequent pages via a POST
(more secure) or GET, you can maintain state. Each page must be
responsible for checking the validity of the key obtained from the
browser via a cookie or via POST or GET.

http://nl2.php.net/manual/en/ref.session.php has a more extensive
discussion.

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Aug 11 '05 #2
Michael Vilain wrote:
Since web servers don't retain state from page to page, it is up to the
browser or the application to maintain the state if needed. Browsers
can do so with a cookie. Alternatively, if you code the application to
transfer a session key created on login to subsequent pages via a POST
(more secure) or GET, you can maintain state. Each page must be
responsible for checking the validity of the key obtained from the
browser via a cookie or via POST or GET.


Hi Michael,

I have a question:
Why do you say that passing PHPSESSID via POST is more safe than via a
COOKIE?

Or do you mean that passing the PHPSESSID via POST is more secure than GET?

I am curious why you say that.

I mean: the request to the webbrowser send the GET, POST and COOKIE, all
unencrypted (unless you use shhtp of course), so it all sounds very unsafe
to me as far a sessionhijacking goes.

By the way:
One tip a friend once gave me (Rein Velt) is storing the remote IP-adres
(the the client's IP) also in the session, and always compare it before
using session. :-)

Regards,
Erwin

Aug 11 '05 #3
>> Since web servers don't retain state from page to page, it is up to the
browser or the application to maintain the state if needed. Browsers
can do so with a cookie. Alternatively, if you code the application to
transfer a session key created on login to subsequent pages via a POST
(more secure) or GET, you can maintain state. Each page must be
responsible for checking the validity of the key obtained from the
browser via a cookie or via POST or GET.
Hi Michael,

I have a question:
Why do you say that passing PHPSESSID via POST is more safe than via a
COOKIE?

Or do you mean that passing the PHPSESSID via POST is more secure than GET?


I think the OP meant that POST is more secure than GET. GET leaves
the session ID in stored URLs in the browser history. POST does
not. Cookies with a duration longer than for a browser session
also get left around in files, although this is much less obvious
than leaving it in the browser history. Sessions, however done
(GET, POST, COOKIE), with a short timeout are less vulnerable to
spoofing since spoofing an expired session does no good whatever.
I mean: the request to the webbrowser send the GET, POST and COOKIE, all
unencrypted (unless you use shhtp of course), so it all sounds very unsafe
to me as far a sessionhijacking goes.
Session hijacking does not have to be done by sniffing the wire.
It could be done by using the same computer after the original user
leaves (think about Internet Cafes, or families with less than one
computer per family member). Thus, session IDs left in browser
history or cookies that last longer than the session can be read,
by other users or perhaps by spyware. Browser URLs (including the
session ID, if done with GET) may get cut-and-pasted into email or
news posts when the user decides to tell his friends about something
interesting he found on the web.
One tip a friend once gave me (Rein Velt) is storing the remote IP-adres
(the the client's IP) also in the session, and always compare it before
using session. :-)


That may block legitimate users using a round-robin proxy (different
requests come from different IPs, even including pieces of the same
page). AOL users would have problems with this, I believe, and
they aren't the only ones. ISPs can inject proxies into the http
path without users knowing about it or having to change their browser
settings. (Router magic to redirect the traffic to go through the
proxy.)

Some users even PAY for a proxy that uses a compressed protocol
between the proxy and the user's browser with some add-on software
("web accelerators"), although they may not realize that's how it
works. Decent software for this does not cache pages requiring
authentication. Nor does it cache https. If someone tries caching
https, and the user is paying attention, they may notice that the
certificate is different (that of the proxy, not the site they
requested) for such a man-in-the-middle attack on https.

The browser may pop up warnings in this situation. How many people
will notice this? Not very many people noticed when I put up a
secure site with a home-grown certificate for "Satan, Prince of
Darkness" with an address in Hell. And this was a prototype
E-commerce site (none of the order-taking or credit-card charging
stuff ever got done) I was asking them to check out.

Also, the IP check is less than 100% effective against spoofing:
office users spoofing each other behind a NAT gateway all may have
the same public IP, and users of the same proxy have the same IP.

The fact that it's less than 100% effective shouldn't discourage
you, but the fact that you lock out legitimate users might. If
it's an intranet application, you may not care that AOL users can't
use it. If it's an E-commerce site, you (or your employer) may be
upset to realize you've locked out AOL users from buying from you.

Gordon L. Burditt
Aug 11 '05 #4
In article <42***********************@news.xs4all.nl>,
Erwin Moller
<si******************************************@spam yourself.com> wrote:
Michael Vilain wrote:
Since web servers don't retain state from page to page, it is up to the
browser or the application to maintain the state if needed. Browsers
can do so with a cookie. Alternatively, if you code the application to
transfer a session key created on login to subsequent pages via a POST
(more secure) or GET, you can maintain state. Each page must be
responsible for checking the validity of the key obtained from the
browser via a cookie or via POST or GET.


Hi Michael,

I have a question:
Why do you say that passing PHPSESSID via POST is more safe than via a
COOKIE?

Or do you mean that passing the PHPSESSID via POST is more secure than GET?

I am curious why you say that.

I mean: the request to the webbrowser send the GET, POST and COOKIE, all
unencrypted (unless you use shhtp of course), so it all sounds very unsafe
to me as far a sessionhijacking goes.

By the way:
One tip a friend once gave me (Rein Velt) is storing the remote IP-adres
(the the client's IP) also in the session, and always compare it before
using session. :-)

Regards,
Erwin


Your friend's advice is good. I'd listen to them.

Sorry for the unclear English. I meant that without cookies, all you
have to communicate between sessions are hidden fields and GET/POST
methods. If you use GET, the session ID is displayed in the URL which
isn't as secure as using the session ID as a hidden field and obtaining
it through a POST. I wasn't thinking specifically of PHPSESSID but one
you've coded yourself.

If you use IP address and some other info run through MD5, you can make
a quite secure session ID.

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Aug 11 '05 #5
Gordon Burditt wrote:
Since web servers don't retain state from page to page, it is up to the
browser or the application to maintain the state if needed. Browsers
can do so with a cookie. Alternatively, if you code the application to
transfer a session key created on login to subsequent pages via a POST
(more secure) or GET, you can maintain state. Each page must be
responsible for checking the validity of the key obtained from the
browser via a cookie or via POST or GET.
Hi Michael,

I have a question:
Why do you say that passing PHPSESSID via POST is more safe than via a
COOKIE?

Or do you mean that passing the PHPSESSID via POST is more secure than
GET?


Hi Gordon, thanks for your warning.

I wasn't aware of any round-robin proxies that result in a changed IP-adres
for the same session.
Strange setup... I must say I do not like it.
But that is my problem, not your's of course. :-)

One thing: The fact that many people share the same IP doesn't frustrate the
setup I described. The fact that a SESSION has an IP stored, doesn't mean
that every IP can only be used once.
It is only ment as a way to make sure the IP stays the same during one
session.

But of course, the AOL-members and roundrobin proxies are a real concern.

Thanks for your advise.
:-)

Regards,
Erwin Moller

I think the OP meant that POST is more secure than GET. GET leaves
the session ID in stored URLs in the browser history. POST does
not. Cookies with a duration longer than for a browser session
also get left around in files, although this is much less obvious
than leaving it in the browser history. Sessions, however done
(GET, POST, COOKIE), with a short timeout are less vulnerable to
spoofing since spoofing an expired session does no good whatever.
I mean: the request to the webbrowser send the GET, POST and COOKIE, all
unencrypted (unless you use shhtp of course), so it all sounds very unsafe
to me as far a sessionhijacking goes.


Session hijacking does not have to be done by sniffing the wire.
It could be done by using the same computer after the original user
leaves (think about Internet Cafes, or families with less than one
computer per family member). Thus, session IDs left in browser
history or cookies that last longer than the session can be read,
by other users or perhaps by spyware. Browser URLs (including the
session ID, if done with GET) may get cut-and-pasted into email or
news posts when the user decides to tell his friends about something
interesting he found on the web.
One tip a friend once gave me (Rein Velt) is storing the remote IP-adres
(the the client's IP) also in the session, and always compare it before
using session. :-)


That may block legitimate users using a round-robin proxy (different
requests come from different IPs, even including pieces of the same
page). AOL users would have problems with this, I believe, and
they aren't the only ones. ISPs can inject proxies into the http
path without users knowing about it or having to change their browser
settings. (Router magic to redirect the traffic to go through the
proxy.)

Some users even PAY for a proxy that uses a compressed protocol
between the proxy and the user's browser with some add-on software
("web accelerators"), although they may not realize that's how it
works. Decent software for this does not cache pages requiring
authentication. Nor does it cache https. If someone tries caching
https, and the user is paying attention, they may notice that the
certificate is different (that of the proxy, not the site they
requested) for such a man-in-the-middle attack on https.

The browser may pop up warnings in this situation. How many people
will notice this? Not very many people noticed when I put up a
secure site with a home-grown certificate for "Satan, Prince of
Darkness" with an address in Hell. And this was a prototype
E-commerce site (none of the order-taking or credit-card charging
stuff ever got done) I was asking them to check out.

Also, the IP check is less than 100% effective against spoofing:
office users spoofing each other behind a NAT gateway all may have
the same public IP, and users of the same proxy have the same IP.

The fact that it's less than 100% effective shouldn't discourage
you, but the fact that you lock out legitimate users might. If
it's an intranet application, you may not care that AOL users can't
use it. If it's an E-commerce site, you (or your employer) may be
upset to realize you've locked out AOL users from buying from you.

Gordon L. Burditt


Aug 12 '05 #6
Michael Vilain wrote:
In article <42***********************@news.xs4all.nl>,
Erwin Moller
<si******************************************@spam yourself.com> wrote:
Michael Vilain wrote:
> Since web servers don't retain state from page to page, it is up to the
> browser or the application to maintain the state if needed. Browsers
> can do so with a cookie. Alternatively, if you code the application to
> transfer a session key created on login to subsequent pages via a POST
> (more secure) or GET, you can maintain state. Each page must be
> responsible for checking the validity of the key obtained from the
> browser via a cookie or via POST or GET.
Hi Michael,

I have a question:
Why do you say that passing PHPSESSID via POST is more safe than via a
COOKIE?

Or do you mean that passing the PHPSESSID via POST is more secure than
GET?

I am curious why you say that.

I mean: the request to the webbrowser send the GET, POST and COOKIE, all
unencrypted (unless you use shhtp of course), so it all sounds very
unsafe to me as far a sessionhijacking goes.

By the way:
One tip a friend once gave me (Rein Velt) is storing the remote IP-adres
(the the client's IP) also in the session, and always compare it before
using session. :-)

Regards,
Erwin


Hi,
Your friend's advice is good. I'd listen to them.

Sorry for the unclear English.
No problem. I understand now what you were saying.

I meant that without cookies, all you
have to communicate between sessions are hidden fields and GET/POST
methods. If you use GET, the session ID is displayed in the URL which
isn't as secure as using the session ID as a hidden field and obtaining
it through a POST. I wasn't thinking specifically of PHPSESSID but one
you've coded yourself.

If you use IP address and some other info run through MD5, you can make
a quite secure session ID.

Yes,

Please read the warning Gordon Burditt gave me (us).

The setup will frustrate a certain percentage of users: The ones on AOL and
the ones that use roundrobin-proxy.

Regards,
Erwin Moller

Aug 12 '05 #7
>Hi Gordon, thanks for your warning.

I wasn't aware of any round-robin proxies that result in a changed IP-adres
for the same session.
Strange setup... I must say I do not like it.
Proxies like this are often set up using router magic (and the
customer may not know he's using a proxy at all). Routers don't
have a lot of memory to keep track of state, like <this ip> is using
<this proxy>, so route all his requests there. Also, it evens out
the load more if it's done on a request-by-request basis. And you
want to use a different proxy if the one in use goes down.
But that is my problem, not your's of course. :-)

One thing: The fact that many people share the same IP doesn't frustrate the
setup I described. The fact that a SESSION has an IP stored, doesn't mean
that every IP can only be used once.
It is only ment as a way to make sure the IP stays the same during one
session.


No, shared IPs don't lock out legitimate users. Shared IPs enable
session hijacking between users that share the IP, which was the
original reason for locking the session to the IP in the first
place, wasn't it? Now, I'm not going to say abandon locking the
session to the IP because it's not 100% perfect at preventing session
hijacking. (Credit card validation is nice, too, but it isn't 100%
either, as thieves use stolen credit card numbers) Some people
have abandoned locking the session to the IP because it locks out
legitimate users, but that's a different issue.

You can get a little trickier, say, by locking the session to *AOL*
rather than a specific AOL proxy. That limits session hijacking
to other AOL customers. It does, however, require somehow coming
up with a list of AOL proxies. Reverse DNS and a look at your web
logs might help with this.

Also, recording (logging) the IP (without DOING anything with it)
is not a bad idea either, especially when a user does something
sensitive and important (like changing a password, ordering something
that costs money, deleting stuff, or even just logging in). It
doesn't stop mischief but it leaves logs that might help you close
the hole afterwards. Is it reasonable that someone would order dialup
service from an ISP that serves only the USA from an Asian IP using
a credit card number with an address in France? Is it reasonable
that someone would order dialup service using a credit card later
determined to be stolen from your own help desk's IP?

Oh, when I said that proxies don't cache authenticated pages, I
meant they don't cache pages using authentication that the proxies
know about (like .htaccess/Basic Authentication, or https). They
may not recognize all the schemes used by PHP programmers. They
probably don't cache POST requests, either. They might cache GET
requests, thereby putting an automated session hijacker in the path
of lots of people who have no malicious intent or have any idea
they are doing it.

Gordon L. Burditt
Aug 12 '05 #8

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

Similar topics

27
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate...
2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
5
by: Yossi | last post by:
I want to set the asp session id path property. how can I do that? I mean, asp session id is stored in a cookie and like any other cookie it should have properties (or attributes), how can I...
4
by: yingjian.ma1955 | last post by:
Hi All, According to a book, the cookie without expires lasts the browser session. I think a browser session ends if you close all the browser windows. I setup a cookie without expires in IE6...
3
by: nn | last post by:
Hello I have ASP.Net application configured to use cookies for session. For some reasons I can't move to cookieless model. I need access to session created in this application without cookie. I...
5
by: news.microsoft.com | last post by:
Hi everyone, I need some help (may be in the form of some sample code) for the subject question. I have an ASP.NET/C# application. I need to do quite a few tasks when the session ends. I...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
11
by: Glenn | last post by:
Hi I've been experimenting with managing state using the Session object. I've created a simple WS with a couple of methods, one which sets a string value, another that retrieves it. Each...
7
by: Microsoft Newsserver | last post by:
Hi Folks. I have an issue I need some help with if thats OK. I am running Framework 2.0 using Windows Integrated Security. For most of the application we manage session timeouts without the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.