Checking for Cookie Support from PHP

Checking for Cookie Support from PHP


Checking for Cookie Support from PHP


  •   < ? php
         if(!isset($_GET['testcookie']))
         {
           setcookie("testcookie", "test value");
           header("Location: {$_SERVER["PHP_SELF"]}?testcookie=1");
           exit;
         }
         else
         {
           if(isset($_COOKIE['testcookie']))
           {
             setcookie("testcookie");
             echo "You have cookies enabled";
           }
           else
           {
             echo "You do not support cookies!";
           }
         }
      ? >

Reading all cookie values


  •   < ? php
         foreach ($_COOKIE as $cookie_name => $cookie_value)
         {
           print "$cookie_name = $cookie_value
    ";
         }
      ? > 

Still Logged In with cookie

  • < ? php
         $auth = $_COOKIE['auth'];
         header( "Cache-Control:no-cache" );
         if( ! $auth == "ok" )
         {
           header("Location:login.php" );
           exit();
         }
      ? > 

Printing a cookie value

  •  < ? php
         print 'Hello, ' . $_COOKIE['userid'];
       ?> 

Reading a cookie value

  •   < ? php
        if (isset($_COOKIE['flavor']))
        {
           print "You ate a {$_COOKIE['flavor']} cookie.";
        }
      ?> 
Checking for Cookie Support from PHP Checking for Cookie Support from PHP Reviewed by Abdul hanan on 06:59:00 Rating: 5

No comments:

Powered by Blogger.