IE8 cannot log on to the website
After the release of IE8, we found that some websites that are used normally in sites such as IE7, IE6, and Firefox cannot log on to IE8.
The reason is that IE8 does not recognize the setcookie.
Bool setcookie (string $ name [, string $ value [, int $ expire = 0 [, string $ path [, string $ domain [, bool $ secure = false [, bool $ HTTPOnly = false])
When setting the domain address, we like to use '/' instead of the entire domain name, but this statement is not recognized in IE8.
Correct Writing Method: .imphper.cn indicates that the entire domain name includes a subdomain name or www.imphper.cn indicates the directory under www.imphper.cn.
From PHP Manual
Description
Bool setcookie (string $ name [, string $ value [, int $ expire = 0 [, string $ path [, string $ domain [, bool $ secure = false [, bool $ HTTPOnly = false])
Setcookie () defines a cookie to be sent along with the rest of the HTTP headers. like other headers, cookies must be sent before any output from your script (this is a protocol restriction ). this requires that you place callto this function prior to any output, including <HTML> and
Name
The name of the cookie.
Value
The value of the cookie. this value is stored on the clients computer; Do not store sensitive information. assuming the name is 'cookiename', this value is retrieved through $ _ cookie ['cookiename']
Expire
The time the cookie expires. this is a UNIX timestamp so is in number of seconds since the epoch. in other words, you'll most likely set this with the time () function plus the number of seconds before you want it to expire. or you might use mktime (). time () + 60*60*24*30 will set the cookie to expire in 30 days. if set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes ).
Note: You may notice the expire parameter takes on a Unix timestamp, as opposed to the date format wdy, DD-mon-yyyy hh: mm: ss gmt, this is because PHP does this conversion internally.
Expire is compared to the client's time which can differ from server's time.
Path
The path on the server in which the cookie will be available on. if set to '/', the cookie will be available within the entire domain. if set to '/Foo/', the cookie will only be available within the/Foo/directory and all sub-directories such as/Foo/BAR/of domain. the default value is the current directory that the cookie is being set in.
Domain
The domain that the cookie is available. to make the cookie available on all subdomains of example.com then you 'd set it to '.example.com '. the. is not required but makes it compatible with more browsers. setting it to www.example.com will make the cookie only available in the WWW subdomain. refer to tail matching in the» spec for details.
Secure
Indicates that the cookie shocould only be transmitted over a secure HTTPS connection from the client. when set to true, the cookie will only be set if a secure connection exists. the default is false. on the server-side, it's on the programmer to send this kind of cookie only on secure connection (e.g. with respect to $ _ server ["HTTPS"]).
HTTPOnly
When true the cookie will be made accessible only through the HTTP protocol. this means that the cookie won't be accessible by scripting versions, such as JavaScript. this setting can perform tively help to reduce identity theft through XSS attacks (although it is not supported by all browsers ). added in PHP 5.2.0. true or false
Return values
If output exists prior to calling this function, setcookie () will fail and return false. if setcookie () successfully runs, it will return true. this does not indicate whether the user accepted the cookie.
Examples
Some examples follow how to send cookies:
Example #1 setcookie () Send example
<? PHP
$ Value = 'something from somewhere ';
Setcookie ("testcookie", $ value );
Setcookie ("testcookie", $ value, time () + 3600);/* expire in 1 hour */
Setcookie ("testcookie", $ value, time () + 3600 ,"/~ Rasmus/"," .example.com ", 1 );
?>
Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is wrongly Ed, it is automatically decoded and assigned to a variable by the same name as the cookie name. if you don't want this, you can use setrawcookie () instead if you are using PHP 5. to see the contents of our test cookie in a script, simply use one of the following examples:
<? PHP
// Print an individual cookie
Echo $ _ cookie ["testcookie"];
Echo $ http_cookie_vars ["testcookie"];
// Another way to debug/test is to view all cookies
Print_r ($ _ cookie );
?>
Example #2 setcookie () delete example
When deleting a cookie you shoshould assure that the expiration date is in the past, to trigger the removal mechanic in your browser. Examples follow how to delete cookies sent in previous example:
<? PHP
// Set the expiration date to one hour ago
Setcookie ("testcookie", "", time ()-3600 );
Setcookie ("testcookie", "", time ()-3600 ,"/~ Rasmus/"," .example.com ", 1 );
?>
Example #3 setcookie () and Arrays
You may also set array cookies by using array notation in the cookie name. this has the effect of setting as your cookies as you have array elements, but when the cookie is stored ed by your script, the values are all placed in an array with the cookie's name:
<? PHP
// Set the cookies
Setcookie ("Cookie [three]", "cookiethree ");
Setcookie ("Cookie [two]", "cookietwo ");
Setcookie ("Cookie [one]", "cookieone ");
// After the page reloads, print them out
If (isset ($ _ cookie ['cookies']) {
Foreach ($ _ cookie ['cooker'] as $ name => $ value ){
Echo "$ name: $ value <br/>/N ";
}
}
?>
The above example will output:
Three: cookiethree
Two: cookietwo
One: cookieone