473,699 Members | 2,181 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 4711
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
7784
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 = ""; echo "<form method='POST' action='login.php'>
27
7118
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 user accesses it (not just once and then store it in the session). If a secure app is multi-page,...
14
4067
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 session from the first browser. I've tried deleting all cookies and any cached pages, but still get the...
2
3343
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 don;t know how to do it?
14
1868
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 by writing data to a database or by passing data from one page to the next with hidden fields. Can...
2
1859
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 to zero, and adding or subtracting one from the counter. - We were trying to determine when a "NEW...
4
2758
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 querystring I'd like to detect it using data sent in every request. One idea I had was that when...
7
2010
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 URL. The author also almost always talks about the method being dependent on the user's...
11
3651
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 application, in between setting the string value and attempting to
0
8700
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8931
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7767
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5878
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4635
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3064
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
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.