Cookies
A cookie is often used to identify a user. Cookies are text files stored on the client computer and they are kept of use tracking purpose.
Each time the same computer requests a page with a browser, it will send the cookie too. PHP transparently supports HTTP cookies.
A cookie is a small file that the server embeds on the user's computer.
Server script sends a set of cookies to the browser.
such as user name ,password etc.
Browser stores this information on local machine for future use.
How to Create a Cookie?
** The setcookie() function must appear before the <html> tag.
setcookie(name, value, expire, path, domain, security);
There are six arguments explain in detail below.
Name - This sets the name of the cookie and is stored in an environment variable called HTTP_COOKIE_VARS. This variable is used while accessing cookies.
Value -This sets the value of the named variable and is the content that you actually want to store.
Expiry – This specify a future time in seconds since 00:00:00 GMT on 1st Jan 1970. After this time cookie will become inaccessible. If this parameter is not set then cookie will automatically expire when the Web Browser is closed.
Path -This specifies the directories for which the cookie is valid. A single forward slash character permits the cookie to be valid for all directories.
Domain - This can be used to specify the domain name in very large domains and must contain at least two periods to be valid. All cookies are only valid for the host and domain which created them.
Security – This can be set to 1 to specify that the cookie should only be sent by secure transmission using HTTPS otherwise set to 0 which mean cookie can be sent by regular HTTP.
Syntax
setcookie(name, value, expire, path, domain,security);
Example
Generaly we use three orgument because of other three orgument used in web servers not in local machines.
<?php
setcookie("cookies_name", "umar farooque khan", time()+3600);
?>
<html>
<head>
.............
.............
</html>
setcookie(name, value, expire, path, domain,security);
Example
Generaly we use three orgument because of other three orgument used in web servers not in local machines.
<?php
setcookie("cookies_name", "umar farooque khan", time()+3600);
?>
<html>
<head>
.............
.............
</html>
