473,396 Members | 1,917 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.

Detecting no session cookies supported by browser

Tom
Hi,

I would like to use the standard PHP sessions and I understand they rely on
the target web browser to support session cookies.

I have tried the following code:

<?
session_start();
if (!session_id()) { //no support for session
header("Location: nocookie.php");
exit();
} else { //session open
....
}
}

echo "cookie ok, user logged as ".$_SESSION['uid'];

?>

I wanted to reroute the user to a "nocookie" page (advice page) if their web
browser does not support cookies, but it does not seem to work, even if I
put IE in the hightest privacy settings.

I know PHP can also use the URL to maintain sessions, but this does not work
very well in my experience.

Any ideas on how to detect no support of session cookies, on one single
page?

Thanks,
Tom
Jul 17 '05 #1
2 4689
You cannot detect if cookies are enabled with a single operation. You must
write to a cookie in one script, then test for that cookie in a second
script.

PHP sessions can work even if the target browser does not allow cookies,
permanent or session-temporary, using a technique known as URL rewriting.
Read the manual at http://www.php.net/manual/en/ref.session.php for details.

--
Tony Marston

http://www.tonymarston.net

"Tom" <To*@nospam.com> wrote in message
news:41***********************@news-text.dial.pipex.com...
Hi,

I would like to use the standard PHP sessions and I understand they rely
on the target web browser to support session cookies.

I have tried the following code:

<?
session_start();
if (!session_id()) { //no support for session
header("Location: nocookie.php");
exit();
} else { //session open
...
}
}

echo "cookie ok, user logged as ".$_SESSION['uid'];

?>

I wanted to reroute the user to a "nocookie" page (advice page) if their
web browser does not support cookies, but it does not seem to work, even
if I put IE in the hightest privacy settings.

I know PHP can also use the URL to maintain sessions, but this does not
work very well in my experience.

Any ideas on how to detect no support of session cookies, on one single
page?

Thanks,
Tom

Jul 17 '05 #2
PHP sessions does not rely on the browser. sessions depends on the
servers configuration. Your'e thinkin' of ordinary cookies.

<?
session_start(); // remember, this is a header!

$_SESSION['uid'] = $maybe_a_mysql_result;

echo 'user logged in as '.$_SESSION['uid'];

unset($_SESSION['uid']); //for a logout script maybe, this will unset
that session

?>

--
Dan Storm

http://err0r.dk
st***@err0r.dk

PGP Public key at http://err0r.dk/pubring.pkr


Jul 17 '05 #3

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

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
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...
14
by: Darrin J Olson | last post by:
I am trying to end a session for a site without having to completely close the browser to end it. When I access the site and log in it works fine. If I log out and in with a different account...
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...
14
by: qaz | last post by:
I've always used session cookies in my web sites. However, since more and more people (including me) are starting to disable cookies, I'm beginning to think that I should change my ways and design...
2
by: Dinkster | last post by:
BackGround: - We are new to ASP - We thought we would experiment with using the session object (in proc) to store a small amount of data. - We get different results when cookieless is set to...
4
by: Chris | last post by:
When a request comes into a page on my ASP.net site and a session is not found, I want to detect whether the request is an initial request or if the user did have a session going that has now been...
7
by: Marcus | last post by:
I know that when you start a session in PHP, the "cookie" it creates is not the same as those that are stored in your browser's temp folder, and instead is kept in RAM. I am confused because in...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.