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

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 100
    Comment on it

    Cookie is a small file that identifies the users on the user's computer.
    whenever the same computer request to the server for the same page, the browser will send the cookie with the request.

    To create Cookie we can use the setcookie() function.

    Syntax

    setcookie(name, value, expire, path, domain, secure, httponly);
    

    To modify a cookie use the same function setcookie() with different argument values. If we required to delete the cookie after a certain time we can set expiration time in that function.

    for example :

    <!DOCTYPE html>
    <?php
    $cookie_name = "user";
    $cookie_value = "Arjun";
    setcookie($cookie_name, $cookie_value, time() + (36400 * 30), "/"); 
    ?>
    <html>
    <body>
    
    <?php
    if(!isset($_COOKIE[$cookie_name])) {
          echo "Cookie named '" . $cookie_name . "' is not set!";
    } else {
          echo "Cookie '" . $cookie_name . "' is set!<br>";
          echo "Value is: " . $_COOKIE[$cookie_name];
    }
    ?>
    </body>
    </html>
    

 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: