473,545 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Locatio n: 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 4699
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("Locatio n: 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
7771
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: ---------------------------------------------------------------------------- <?php ini_set("session.use_cookies", "off"); ini_set("session.use_trans_sid", "on"); session_start(); $_SESSION = ""; $_SESSION =...
27
7091
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 a user from information you got from the session. Each secure app on a site must challenge the user for name and password, each and every time the...
14
4042
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 without closing the browser, I get the first session's information. Also, if a open another browser and log in with a different account I get the...
2
3327
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 the user. I want that cookie should get deleted when user closes the browser without signing out. I think it is done in global.asa file . But i...
14
1858
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 websites without the use of session cookies. I've never done it before, but I understand that we can get around the use of session cookies either...
2
1850
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 "true" veses "false". - Our simple test app involved updating a counter that was stored as an item in the Session Object. We allow resetting the counter...
4
2749
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 lost and show an explanatory message before restarting the session. Rather than tagging a 'session in progress' flag on the end of every request...
7
1990
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 every session tutorial I have ever read, the author invariably mentions the 2 main ways of propagating sessions - through cookies and appended to the...
11
3622
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 method has the WebMethodAttribute.EnableSession set to true. When I run the test page the session is maintained. However, using a console...
0
7475
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7921
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
720
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.