Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create Cookies With PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 101
    Comment on it

    Why we create cookies ?

    cookie is used to identify any user. A cookie is known as a very small file that the server copy into the user's computer browser. Whenever users request a web page using the same computer , it will send the cookie too.

    With PHP, We can create and retrieve cookie values.

    For creating cookie. setcookie() function is called.

    <?php
    $cookie_name = "Username";
    $cookie_value = "David Marker";
    setcookie($cookie_Username, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day // used to create the cookies
    ?>
    

    For retreiving any cookie we can write the code=

    <?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];
    }
    ?>
    

 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: