br3nn4n Posted February 26, 2008 Share Posted February 26, 2008 This can be done, right? I mean it's the only way to do it? Using the $_COOKIE array right? Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/ Share on other sites More sharing options...
revraz Posted February 26, 2008 Share Posted February 26, 2008 $_COOKIE will retrieve info, not set it. You need to use setcookie to set it. Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-477371 Share on other sites More sharing options...
br3nn4n Posted February 27, 2008 Author Share Posted February 27, 2008 Okay, so (sorry I'm only just learning about how PHP works with cookies) I can add to the cookie once it's SET, right? IE: use setcookie() at the beginning of the file (before the HTML headers are sent, I think?) to set the cookie and then add to and retrieve from it later. Yes? Once the cookie is set in the user's browser, it can then be added to can't it? Sorry for all the questions but my poll is gonna be REALLY skewed unless I set some cookies to prevent voting more than once from the same IP. Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-477781 Share on other sites More sharing options...
trq Posted February 27, 2008 Share Posted February 27, 2008 Once the cookie is set in the user's browser, it can then be added to can't it? Ever thought of trying it? Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-477783 Share on other sites More sharing options...
unsider Posted February 27, 2008 Share Posted February 27, 2008 You could possibly require them to log in, and use both cookies and sessions to prevent a skewed graph. Sorry if you've thought of that, but just putting it out there. And yes I'm not quite sure but I think once you set the cookie you can retrieve from it later. And yes you can add more to it once it's set. Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-477784 Share on other sites More sharing options...
br3nn4n Posted February 27, 2008 Author Share Posted February 27, 2008 Once the cookie is set in the user's browser, it can then be added to can't it? Ever thought of trying it? I'm just trying to get a complete grasp over it before I spend any time on it really, so I don't just waste that time. I tried putting it right after the <html> tag but that gave the standard "Warning: Cannot modify header information" error. I just tried putting it before the <html> tag as well and that did the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-478422 Share on other sites More sharing options...
revraz Posted February 27, 2008 Share Posted February 27, 2008 setting the cookie has to be done before any output. "Adding" to it requires another setcookie command. Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-478426 Share on other sites More sharing options...
br3nn4n Posted February 29, 2008 Author Share Posted February 29, 2008 BAM! stupid whitespace, I got it working. Placed it absolutely first, and took out the space after the <?php Okay, so as I understand it the cookie is now there, and that can be verified by using the javascript:alert(document.cookie) command. Now, last thing, where do I go from here? I use the setcookie() function but what do I put inside it? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-480366 Share on other sites More sharing options...
revraz Posted February 29, 2008 Share Posted February 29, 2008 That depends on what you want to store. What are you using it for? Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-480407 Share on other sites More sharing options...
br3nn4n Posted February 29, 2008 Author Share Posted February 29, 2008 either a 0 or a 1, depending on if a user has voted in the poll or not. Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-480430 Share on other sites More sharing options...
revraz Posted February 29, 2008 Share Posted February 29, 2008 Then when they delete the cookie, they can vote again. You should write that type of info to a DB. Quote Link to comment https://forums.phpfreaks.com/topic/93180-add-info-to-cookie-outside-of-headers/#findComment-480433 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.