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
    • 316
    Comment on it

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

    Syntax:

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

    Creating cookies:

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

    Accessing Cookies:

    1. <?php
    2. echo $_COOKIE["name"]. "<br />";
    3.  
    4. /* is equivalent to */
    5. echo $HTTP_COOKIE_VARS["name"]. "<br />";
    6.  
    7. echo $_COOKIE["age"] . "<br />";
    8.  
    9. /* is equivalent to */
    10. echo $HTTP_COOKIE_VARS["name"] . "<br />";
    11. ?>

    Deleting Cookie:

    1. <?php
    2. setcookie( "name", "", time()- 60, "/","", 0);
    3. setcookie( "age", "", time()- 60, "/","", 0);
    4. ?>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: