SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Check if users has cookies/sessions disabled?

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Check if users has cookies/sessions disabled?

    Is there a way to check if the user has cookies/sessions disabled, and if they do, redirect them?

    TIA!

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (!isset($_COOKIE['cookies_enabled']) && !isset($_GET['cookie_test'])) {
        
    // lets set a cookie and try again
        
    setcookie('cookies_enabled''1');
        
    header('Location: ' $_SERVER['PHP_SELF'] . '?cookie_test');
        exit;
    } elseif (!isset(
    $_COOKIE['cookies_enabled']) && isset($_GET['cookie_test'])) {
        
    // we already tried, but they didnt accept our cookie
        // do something
    } else {
        
    // they accepted out cookie

    you need to be careful when doing things like that though. if you included that code in every page its going to cause a lot of redirects for those with cookies disabled unless your make sure to carry ?cookie_test along all the urls in your website.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •