Asked 2 years ago
17 Jun 2021
Views 371
Pietro

Pietro posted

How to make a cookie with PHP

How to make a cookie with PHP
Melyna

Melyna
answered Aug 22 '21 16:23

use setcookie() function to make cookie with PHP .
its very simple to make cookie in PHP

setcookie('set_cookie_variable',"true");

here first argument of setcookie() function : set_cookie_variable is access variable for later use .
and second argument of setcookie() function is cookie value which is "true" in our case.

also can set a time limit for cookie to expire

setcookie('set_cookie_variable',"true",3600);

here you can see the third argument which is cookie expires time. so in the above code cookie will expire in an hour.
as you can see expire time in seconds.

how to make cookies for a specific domain?

setcookie('set_cookie_variable',"true",3600,'data','www.example.com');


the third argument of setcookie() function is the path of a folder for specific domain where cookie is aviliable
the fourth argument of setcookie() function is the domain name , it needs to pass the domain name which specific cookie is needed to make

Post Answer