Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Set up cookies in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 284
    Comment on it

    We can set the cookies with function called setcookie() . This function requires six arguments to be pass.

    Syntax:

    setcookie(name, value, expire, path, domain, security);
    

    Creating cookies:

    <?php
       setcookie("name", "John Watkin", time()+3600, "/","", 0);
       setcookie("age", "36", time()+3600, "/", "",  0);
    ?>
    

    Accessing Cookies:

     <?php
             echo $_COOKIE["name"]. "<br />";
    
             /* is equivalent to */
             echo $HTTP_COOKIE_VARS["name"]. "<br />";
    
             echo $_COOKIE["age"] . "<br />";
    
             /* is equivalent to */
             echo $HTTP_COOKIE_VARS["name"] . "<br />";
          ?>
    

    Deleting Cookie:

    <?php
       setcookie( "name", "", time()- 60, "/","", 0);
       setcookie( "age", "", time()- 60, "/","", 0);
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: