answersLogoWhite

0

Please PHP cookies are a mechanism to store small amount of data via browser on a user computer, usually used for permanent login to websites like Facebook, Twitter, for online shopping etc.

In PHP there are 2 functions for creating a cookie - setcookie() and setrawcookie(). The complete syntax of the setcookie function is

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

The only required parameter is $name, that is the name of the cookie, all other parameters are optional. For example if you want to store the time of the page loading, you can write

setcookie('loaded_time', date('r'));

and if you want to display the cookie content to the browser, you can write

echo $_COOKIE['loaded_time'];

To make the cookie persistent, you must set the third parameter $expire to a long period, for example 3600x24x365 is 1 year, because $expire contains time in seconds:

setcookie('loaded_time', date('r'), time()+3600*24*365);

The function time() returns the number of seconds since January 1, 1970, so this sets the expiration of the cookie to the next year.

The function setrawcookie() does the same, but without urlencoding the cookie value, its syntax is:

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

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

How do you add a comment in PHP?

< ?php // This is an example of comment in PHP /* This is another example of comment in PHP and we can write comments in multiple lines using this method */ ? >


How do you create a cookie and where will it placed in php?

You can set a cookie using the setcookie() function. You can do this as many times as you wish during your script. Remember that the cookie will not be available to PHP until the next time the page is loaded (or the script is called by a new HTTP request). On the next page, you can access the cookie data from the $_COOKIE super-global array. The key will be the name of the cookie, and the value will be the value you assigned to it the last time you set it.


How do you get a cookie on a certain page?

Its an easy PHP code


What are the PHP tags?

There are no PHP tags. Unlike HTML, PHP is not Markup language. They use scripts. An example would be <?php echo "Hello, World!"; ?>


Is a cookie is a special HTML page?

No, a cookie is a temporary note that websites can place(not by HTML but with PHP) that tells the Web Browser to do something when that web page is called upon.


How do you include a file in PHP?

To include a file in PHP all you need to do is use the include() function as I have shown you in the example below. <?php include("filename.php"); ?>


Is PHP an example of a programming language?

Yes.


What art movement was the Persistence of Memory an example of?

Surrealism.


Is persistence common or proper noun?

The noun persistence is a common noun.Any common noun becomes a proper noun when used for the name of a specific person or thing, or a title, for example Persistence Drive in Woodbridge VA or the story 'Persistence of Desire' by John Updike.


WHAT is the difference between session and cookie in php?

The session is stored on the web server. The cookies is stored in a little file on users machine. This means that the session is (relatively) secure, whereas the cookie can be edited by the end user.


What does the acronym Canada PHP mean?

There is no known Canadian acronym for the words Canada PHP. PHP can stand for many things but nothing of significance, for example an organization, that it would mean in Canada.


What character allows you to concatenate strings in PHP?

To concatenate strings in PHP, you use the . (dot) character. For example: $str = "String1" . "String2";