PHP set HttpOnly property of cookies

Source: Internet
Author: User

HttpOnly is Microsoft's extension of cookies. This is primarily a matter of resolving a user's cookie may be compromised.
As we all know, when we go to the mailbox or forum login, the server will write some cookies to our browser, when the next time we visit other pages, because the browser automatically pass the cookie, so that a login can see all the need to see the content after landing. In other words, in essence, all the login states are built on cookies! Assuming that the cookie we landed on was acquired, there would be a danger of exposing personal information! Of course, think about how other people can get customers ' cookies? It must be a program of malicious people running in the browser! If it is now flying rogue software, there is no way, httponly is not to solve this situation, it is used to solve the browser JavaScript access cookie problem. Imagine a flash program running in your browser to get your cookie!
IE6 's SP1 with the support of HttpOnly, so the relative also said that still some security.

Settings in PHP
PHP5.2 above has supported the setting of the HttpOnly parameter, also supports the setting of global HttpOnly, in php.ini
-----------------------------------------------------
Session.cookie_httponly =
-----------------------------------------------------
Setting its value to 1 or true to turn on the HttpOnly property of the global cookie, and of course, supports the opening of the Code:
-----------------------------------------------------
<?php  ini_set ("Session.cookie_httponly", 1);
or  session_set_cookie_params (0, NULL, NULL, NULL, TRUE);
?>
-----------------------------------------------------
The cookie manipulation function Setcookie function and the Setrawcookie function are also specifically added with the 7th parameter as an option for HttpOnly, with the opening method:
-------------------------------------------------------
Setcookie ("abc", "Test", NULL, NULL, NULL, NULL, TRUE);
Setrawcookie ("abc", "Test", NULL, NULL, NULL, NULL, TRUE);
-------------------------------------------------------
For previous versions of PHP5.1 and PHP4 versions, you need to use the header function to work around the following:
-------------------------------------------------------------
<?php  Header ("Set-cookie:hidden=value; HttpOnly ");  ? >
-------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.