Setup Menus in Admin Panel

  • No products in the cart.

  • LOGIN

PHP Cookies

Cookies

Cookies are a mechanism for storing data in the remote browser and thus tracking or identifying return users.

Cookie is created at server side and saved to the client side.Browser stores this information on local machine for future use.

You can set cookies using the functions:

  • setcookie() or
  • setrawcookie() function.

PHP setcookie() function

PHP setcookie() function is used to set cookie with HTTP response. Once cookie is set, you can access it by $_COOKIE superglobal variable.

Syntax:

bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path 
[, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )

Example:`

setcookie("CookieName", "CookieValue");/* defining name and value only*/
setcookie("CookieName", "CookieValue", time()+1*60*60);//using expiry in 1 hour(1*60*60 seconds or 3600 seconds)
setcookie("CookieName", "CookieValue", time()+1*60*60, "/mypath/", "abc.com", 1);

 

How Cookies are passed in the HTTP protocol?

The server sends the following in its response header to set a cookie field.
Set-Cookie:name=value
If there is a cookie set, then the browser sends the following in its request header.
Cookie:name=value

ASSIGNMENT : How will you make a check that a cookie is set or not? MARKS : 10  DURATION : 1 week, 3 days

ASSIGNMENT : How will you set cookies using PHP? MARKS : 10  DURATION : 1 week, 3 days

ASSIGNMENT : How will you get cookies using PHP? MARKS : 10  DURATION : 1 week, 3 days

ASSIGNMENT : How will you delete a cookie? MARKS : 10  DURATION : 1 week, 3 days

ASSIGNMENT : What is the purpose of $_COOKIE variable in PHP? MARKS : 5  DURATION : 10 minutes

SEE ALL Add a note
YOU
Add your Comment
 

Advanced Course Search Widget

Popular Courses

Course Categories

© PHPhelp. 2002 - 2018 All rights reserved.
X