Connecting Tech Pros Worldwide Forums | Help | Site Map

Detecting no session cookies supported by browser

Tom
Guest
 
Posts: n/a
#1: Jul 17 '05
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


Tony Marston
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Detecting no session cookies supported by browser


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" <Tom@nospam.com> wrote in message
news:41444afb$0$20250$cc9e4d1f@news-text.dial.pipex.com...[color=blue]
> 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
>[/color]


Dan Storm
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Detecting no session cookies supported by browser


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
storm@err0r.dk

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




Closed Thread