The syntax is :
setcookie(name, value, expire, path, domain);
And then to return it:
echo $_COOKIE["user"];
And a way to view all cookies is:
print_r($_COOKIE);
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.
Its an easy PHP code
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.
header() is a php function used to modify and set HTTP headers sent to the browser.
we cant use set timeout function in php because it is of java script function
Rasmus Lerdorf created PHP (Hypertext Preprocessor) in 1994. Initially, it was a set of Perl scripts, which later evolved into the PHP we know today.
You can set a cookie using the "setcookie()" function, which takes the following arguments:setcookie($name, $value, $lifetime, $path, $domain, $secure, $httponly);$name = The name of the cookie (String)$value = (Optional) The value of the cookie, like a username or code (String)$lifetime = (Optional) The lifetime of the cookie (Integer of seconds)$path = (Optional) The directory / path of a server, in which the cookie will be available in (String)$domain = (Optional) The domain name at which the cookie is available at (String)$secure = (Optional) Determines whether the cookie should only be sent while there is a secure connection (If you don't know what this is, just make it false) (Boolean)$httponly = (Optional) Determines whether the cookie can only be accessed through the HTTP protocol, and not by other scripting languages like JavaScript or VBScript (Boolean)The only arguments you need to focus on here, for starters, is the $name, $value, and $lifetime. All other arguments are optional and can be left alone, just for the purpose of learning how to set a cookie.Here is an example of how you could set up a cookie:Setting a cookiesetcookie('mycookie', 'hello', time()+3600);We set the name of the cookie to "mycookie".We said the value of the cookie is "hello".We said that the cookie should expire at the current time + 3,600 seconds. This means that the cookie should delete itself after 3,600 seconds.Displaying a cookie's valueNow that you have set the cookie, your going to need to retrieve it. When you send a cookie, it won't be available on the same page - you must go to another page, or refresh the page, to have the cookie truly "set".The $_COOKIE variable contains all the values of every cookie, stored on a user's computer, that is available to the website.You can access a specific cookie by putting it's name into the $_COOKIE array. For example, in our case, we would say $_COOKIE['mycookie'] to retrieve our cookie information.echo $_COOKIE['mycookie']; // Displays "hello"Changing the value of a cookieYou can also alter the value of a cookie by "setting" the cookie again, but with a different value.setcookie('mycookie', 'its a different value!', time()+3600);Deleting a cookieAnd, of course, you may want to delete cookies. There isn't a specific delete-cookie function. However, you can "set" the cookie again, and specify a time in the past - so then the browser should immediately dispense of the cookie.You won't need a value, since it's going to delete itself anyway. You can go ahead and set it to the NULL constant (or, give it a value - either way works).setcookie('mycookie', NULL, time()-3600);// orsetcookie('mycookie', 'goodbye', time()-3600);// orsetcookie('mycookie');For more information about cookies, see the PHP and w3schools references, respectively listed.[ http://www.php.net/setcookie ][ http://www.w3schools.com/PHP/php_cookies.asp ]
Set up a PHP file and put the following in it. <?php phpinfo(); ?> Then run it on the server, it will have all the information you will need including what version you are running.
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.
A PHP computer system is simply a set of computers using the PHP programming language. It is used in over 200 million websites currently and was created in 1995.
set it down
A framework in PHP is a set of prebuilt classes and functions (like cakePHP.org or codeignitor) that let's you add basic classes and write less do more.