setcookie php
setcookie($cookiename, $cookievalue, time() + (86400 * 30), "/"); // 86400 = 1 day
setcookie php
setcookie($cookiename, $cookievalue, time() + (86400 * 30), "/"); // 86400 = 1 day
php cookies
//Cookies
//Cookies are stored on the client side. cookies are not as secure as sessions
//and it is recommended that you use sessions as much as possible.
====================
Version 1 for cookies
====================
<?php
if(isset($_COOKIE['nameofcookie'])){
echo 'User ' . $_COOKIE['nameofcookie'] . ' is set<br>';
}else{
echo'User is not set';
}
====================
Version 2 for cookies
====================
<?php
//to change cookie
setcookie('nameofcookie','Frank', time() + (86400 *30));//set for a day
if(isset($_COOKIE['nameofcookie'])){
echo 'User ' . $_COOKIE['nameofcookie'] . ' is set<br>';
}else{
echo'User is not set';
}
=======================
Version 3 for cookies
=======================
<?php
//to change cookie
setcookie('nameofcookie','Frank', time() + (86400 *30));//set for a day
//to unset a cookie just set the time that is already past
//delete cookie
setcookie('nameofcookie','Frank', time() -3600);
if(isset($_COOKIE['nameofcookie'])){
echo 'User ' . $_COOKIE['nameofcookie'] . ' is set<br>';
}else{
echo'User is not set';
}
=========================
Version 4 check for cookies
=========================
<?php
//to change cookie
setcookie('nameofcookie','Frank', time() + (86400 *30));//set for a day
if(count($_COOKIE) > 0){
echo 'There are ' . count($_COOKIE) . ' cookies saved<br>';
}else{
echo 'There are no cookies saved<br>';
}
if(isset($_COOKIE['nameofcookie'])){
echo 'User ' . $_COOKIE['nameofcookie'] . ' is set<br>';
}else{
echo'User is not set';
}
set cookies function in php
//Parameter of Cookie
//only first line is usable other lines is for descrption
setcookie($cookiename ,$cookievalue , time() + (86400 * 10) , "/" , domain.com ,True , False);
//Explanation
setcookie(name , value, time, path, domain , secure, httponly)
1.name is the name of cookie
2.value is the value that you want to save in cookie
3.time is expire time of cookie and it is set in sec so 86400 sec is
equal to 1 day time() function get the current time and 86400 * 10 means
after 10 days cookie will be expire
4.path is path of website to access coookie if we use "/" it means we can
access cookie from every page
5.domain is the domain from which you want to access the cookie if we use
domain then we only access cookie from that specific domain
6.secure means HTTPs protocol if its True it means cookie only set if its
HTTPs otherwise cookie cannot set
7.HTTPonly means if its false we can access cookie from localsite(javascript)
and serversite but if its Ture other wise from only serversite (php)
php set cookie
<?php
$name = 'COOKIE_NAME';
$value = 'VALUE';
$expireTime = strtotime('+1 years');
$path = '/';
setcookie($name,$value,$expireTime,$path);
php cookies
//Cookies
//Cookies are stored on the client side. cookies are not as secure as sessions
//and it is recommended that you use sessions as much as possible.
//save addional information as an array in a cookie
<?php
$user = ['name' => 'Brad', 'email' => '[email protected]', 'age' = 35];
$user = serialize($user);
setcookie('user', $user, time() + (86400 *30));
$user = unserialize($_COOKIE['user']);
echo $user['name'];
cookies php syntax
setcookie("cookie_name", "type_on_cookie", expiry_time(), "/");
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us