PHP COOKIES

Sugar babies

PHP COOKIES

  • A cookie is often used to identify a user.
  • A cookie is a small file that the server embeds on the user's computer. 
  • Each time the same computer requests a page with a browser, it will send the cookie too.
  • With PHP, you can both create and retrieve cookie values.
  • A cookie is created with the setcookie() function.

TYPES OF COOKIES IN PHP :

There are three types of computer cookies:                        
  • Persistent
  • Third-party. 
  • Session

SYNTAX FOR COOKIES IN PHP :

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

EXAMPLE FOR COOKIES IN PHP :

<!DOCTYPE html>
<?php
    setcookie("Auction_Item", "Luxury Car", time() + 2 * 24 * 60 * 60);
?>
<html>
<body>
    <?php
        echo "cookie is created."
    ?>
    <p>
        <strong>Note:</strong> 
        You might have to reload the 
        page to see the value of the cookie.
    </p>
  
</body>
</html>

OUTPUT :

cookie is created
Note: You might have to reload the page to see the value of the cookie
Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send