Austen
Austen

Reputation: 293

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");

Upvotes: 1

Views: 1026

Answers (1)

Nerius
Nerius

Reputation: 980

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");

Upvotes: 1

Related Questions