Re: [PHP] Simple cookie question
This may be a stupid question, but I'm trying to set up a system where I can take a poll from visitors to my website and then set a cookie so that they can't vote more than once (until they clear their cookies at least). Problem is, I don't want to put it at the top of my page, because what if somebody opens up a poll but decides not to vote, then later changes his mind. The cookie will prevent him from voting. I want the cookie to be set right after the user clicks the vote button, but every time I do that, I get an error about headers already being sent. Is there any way around this? Does it have to be a cookie? I use the IP address and store that somewhere. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple cookie question
--- Liam Gibbs [EMAIL PROTECTED] wrote: Does it have to be a cookie? I use the IP address and store that somewhere. Please don't. An IP address is a terrible means of user identification. I would explain why, but I think it would be more informative to search through the archives, as previous explanations have been quite good. Chris = Become a better Web developer with the HTTP Developer's Handbook http://httphandbook.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple cookie question
Hello, This is a reply to an e-mail that you wrote on Sun, 10 Aug 2003 at 00:24, lines prefixed by '' were originally written by you. This may be a stupid question, but I'm trying to set up a system where I can take a poll from visitors to my website and then set a cookie so that they can't vote more than once (until they clear their cookies at least). Problem is, I don't want to put it at the top of my page, because what somebody opens up a poll but decides not to vote, then later changes his mind. The cookie will prevent him from voting. I want the cookie to be set right after the user clicks the vote button, but every time I do that, I get an error about headers already being sent. Is there any way around this? You cannot send any headers after you have sent output as this is how HTTP works, a set of headers are sent, double newline, then all the content. You can't go back in time and add more headers. There are two ways round your problem... 1. Set your cookie right at the top of the script, so as your first line have something like: if(isset($_POST['vote'])){ setcookie(); } 2. Use output buffering, this will make PHP buffer all of your content and not send it till you tell it to (or until it reaches the end of the file). Read more at: http://uk.php.net/ref.outcontrol All the best, David. -- phpmachine :: The quick and easy to use service providing you with professionally developed PHP scripts :: http://www.phpmachine.com/ Free PHP error handling script: www.phpmachine.com/error-handler/ Professional Web Development by David Nicholson http://www.djnicholson.com/ QuizSender.com - How well do your friends actually know you? http://www.quizsender.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple cookie question
On Sunday, August 10, 2003, at 01:36 PM, Liam Gibbs wrote: Does it have to be a cookie? I use the IP address and store that somewhere. Liam, please don't advise relying on the IP address for anything. It's been discussed to death on the list before, but in short, the highlights are: 1. users sharing a connection behind a firewall or router will often all have the same IP address 2. users of larger ISPs (AOL being the widely documented example) will often have a new IP address for each request they make Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple cookie question
Assuming that you have a process page that stores the submitted choice, have the process page make the cookie setting and then redirect back to the first page. Or better yet, I like it when my original page never leaves and a popup window is openned to save my choice and then show me the results for that given vote. Jim Lucas - Original Message - From: Matthew Koh [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, August 09, 2003 4:22 PM Subject: [PHP] Simple cookie question This may be a stupid question, but I'm trying to set up a system where I can take a poll from visitors to my website and then set a cookie so that they can't vote more than once (until they clear their cookies at least). Problem is, I don't want to put it at the top of my page, because what if somebody opens up a poll but decides not to vote, then later changes his mind. The cookie will prevent him from voting. I want the cookie to be set right after the user clicks the vote button, but every time I do that, I get an error about headers already being sent. Is there any way around this? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple cookie question
There are two ways round your problem... 1. Set your cookie right at the top of the script, so as your first line have something like: if(isset($_POST['vote'])){ setcookie(); } 2. Use output buffering, this will make PHP buffer all of your content and not send it till you tell it to (or until it reaches the end of the file). Read more at: http://uk.php.net/ref.outcontrol 3. Use PHP's session features. Start your session at the top of the page, like usual, and then set a flag in $_SESSION when the poll is is completed. This will allow you to set other arbitrary flasg as well. See: http://php.net/session - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php