Check if cookies are enabled

Discussion in 'PHP' started by Tony Brar, Sep 27, 2012.

  1. #1
    Solved! View solution.
    Tony Brar, Sep 27, 2012 IP
  2. #2
    Well, seems that it somewhat works....


    Somewhat, because even if cookies are enabled, the first time someone visits your site, it says that cookies are disabled (even if the are enabled)..

    Let's fix that..It's an easy fix...


    First we create a cookie

    
    <?php
    setcookie('test', 1, time()+3600);
    ?>
    
    PHP:
    (Note: this should be the first thing on your site - even before the doctype, else it'll throw a warning that headers are already sent)

    next, we check if there is a cookie with the isset() function

    
    <?php
    if (isset($_COOKIE['test']))
    {
        echo("enabled");
    }
    else
    {
        echo("disabled");
    }
    ?>
    
    PHP:
    Have fun
     
    GMF, Sep 27, 2012 IP
  3. Web Solutions

    Web Solutions Peon

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    0
    #3
    Why don't you simply try it ? Seriously.
     
    Web Solutions, Sep 27, 2012 IP