Jump to content

Cookies and a Self-Submitting Form


makamo66

Recommended Posts

I am using setcookie in a self-submitting form. Once the form is submitted, it sends an email and then it redirects to the next page by using a header. The problem is that the cookies aren't set for the email even though they are set (and displayed) on the next page. I've tried using the following code to reload the page before I send the email but to no avail:

 

setcookie("survey_username", $_POST['yourname'], time() + 31536000, '/survey/', $_SERVER['SERVER_NAME'], 0);

header("Location: ". $_SERVER['PHP_SELF']);

exit;

Link to comment
https://forums.phpfreaks.com/topic/201908-cookies-and-a-self-submitting-form/
Share on other sites

I ended up redirecting with a header to a new page and then only after that sent the mail and then the cookies were set properly. I'm not that happy with the solution though as it meant I had to add three new pages and that seems kind of messy. I should have been able to reload the page after setting the cookies to make it work.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.