makamo66 Posted May 16, 2010 Share Posted May 16, 2010 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 More sharing options...
public-image Posted May 16, 2010 Share Posted May 16, 2010 could you not make the email be sent on the next page? if not then.. Why arent the cookies on during the email or is that another problem? Link to comment https://forums.phpfreaks.com/topic/201908-cookies-and-a-self-submitting-form/#findComment-1058964 Share on other sites More sharing options...
makamo66 Posted May 17, 2010 Author Share Posted May 17, 2010 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. Link to comment https://forums.phpfreaks.com/topic/201908-cookies-and-a-self-submitting-form/#findComment-1059279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.