Detecting no session cookies supported by browser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom

    #1

    Detecting no session cookies supported by browser

    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


  • Tony Marston

    #2
    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

    This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




    "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("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
    >[/color]


    Comment

    • Dan Storm

      #3
      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


      storm@err0r.dk

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




      Comment

      Working...