In PHP how to Create a Cookie?

The setcookie() function is used to set a cookie.

Note: The setcookie() function must appear BEFORE the <html> tag.
Syntax

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

Example


In the example below, we will create a cookie named "user" and assign the value "Alex Porter" to it. We also specify that the cookie should expire after one hour:

<?php
setcookie("user", "Alex Porter", time()+3600);
?>

<html>
<body>

</body>
</html>

No comments:

Post a Comment