By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,497 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,497 IT Pros & Developers. It's quick & easy.

Detecting no session cookies supported by browser

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.