简体   繁体   中英

PHP Cookies not setting

I have a script so when a user enters an incorrect CAPTCHA on the contact me form I have it saves the users form data to a cookie so it can be recalled when the user has to re-enter the CAPTCHA. But it's not saving the cookie, I've checked the Chrome Debugger, and it's not doing anything.

Here's the code, I've checked that the variables are successfully working before anyone asks ;)

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
setcookie("name", $name, time()+3600, "/", "http://pattersoncode.ca");
setcookie("email", $email, time()+3600, "/", "http://pattersoncode.ca");
setcookie("message", $message, time()+3600, "/", "http://pattersoncode.ca");

The problem is the http:// in your domain parameter; it specifies a protocol, namely, HTTP, and is not part of the domain.

If you want set a cookie effective for example.com , subdomain.example.com will only work on that subdomain, while setting .example.com will work on all subdomains (including the root domain).

In short, try with these:

setcookie("name", $name, time()+3600, "/", ".pattersoncode.ca");
setcookie("email", $email, time()+3600, "/", ".pattersoncode.ca");
setcookie("message", $message, time()+3600, "/", ".pattersoncode.ca");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM