Re: Setting Cookie



Thanks Hub,
yea I understand about the buffer, I was just showing that the variable was
being passed.
When I renamed the cookie name/value for the second domain, I mistyped! I
meant to type

if($_GET['video'] == "hide")
instead of
if($_GET['video' == "hide"])
and for some reason, I simply didn't catch it. ;)
LOL, no I changed the domain name for this post, so to remain somewhat
anonymous.
Don't want everyone coming to my site giving me a hard time about not being
able to set a cookie! :)

Thanks again Hub and everyone for your help!

Ridge

"The Hub" <thehub@xxxxxxxxxxxx> wrote in message
news:42e052fc$1@xxxxxxxxxxxxxxxxxxxxxxxxx
> cookies are part of the header, and header info cannot be set after page
> data has been sent to the buffer. if you output $_GET at the beginning of
> the script, even your redirect won't work. make sure there is no line
> break or space or anything output before the cookie (including anything
> before the <? tag).
> are you using 'mydomain.com' in the setcookie? it is optional and defaults
> to wherever you set it from, but if you specify it then it can only be
> read from a page at that domain.
>
> "Ridge Burner" <nospam@xxxxxxxxxx> wrote in message
> news:HoODe.192428$xm3.111400@xxxxxxxxxxxx
>>I used print_r($_GET) at beginning of script and it returns:
>> Array ( [video] => hide )
>> so the var is set, but it is just not setting the cookie.
>> This script is copied from another domain (where it works fine), the only
>> difference between the two being the domain name in the 5th parameter.
>> Do you think I should put the setcookie and the [un]setcookie on
>> different pages like so:
>>
>> PAGE1:
>> setcookie("video", "hide", time()+60*60*24*30*12, '/', 'mydomain.com');
>> header("Location: index.php");
>>
>>
>> &
>>
>> PAGE2:
>> setcookie("video", "hide", time()-(60*60*24*30*12), '/', 'mydomain.com');
>> header("Location: index.php");
>>
>>
>> using: print_r($_COOKIE) || print_r($HTTP_COOKIE_VARS) ||
>> var_dump($_COOKIE) returns 'NULL' when user is redirected to index.php
>>
>> Ridge
>>
>> "The Hub" <thehub@xxxxxxxxxxxx> wrote in message
>> news:42dfada2$1@xxxxxxxxxxxxxxxxxxxxxxxxx
>>> Your problem is here:
>>>
>>> if($_GET['video' == "hide"])
>>>
>>> 'video' == "hide" returns false.
>>> if($_GET[false]) returns false.
>>>
>>> "Ridge Burner" <nospam@xxxxxxxxxx> wrote in message
>>> news:YDNDe.168689$x96.160514@xxxxxxxxxxxx
>>>>I can't for some reason get this cookie to set! Am I not understanding
>>>>the correct way to do this? Here is the script:
>>>>
>>>> <?
>>>> if(isset($_GET['video'])){
>>>> if($_GET['video' == "hide"]){
>>>> setcookie("video", "hide", time()+60*60*24*30*12, '/',
>>>> 'mydomain.com');
>>>> }
>>>> if($_GET['video' == "show"]){
>>>> setcookie("video", "", time()-(60*60*24*30*15), '/',
>>>> 'mydomain.com');
>>>> }
>>>> }
>>>> header("Location: index.php");
>>>> ?>
>>>>
>>>> Any help would be appreciated!
>>>>
>>>> Ridge
>>>>
>>>
>>>
>>
>>
>
>


.



Relevant Pages

  • RE: Win32 DLL project randomly crashes after moving to VS2005
    ... Have you found something when your program crashed with stack overflow ... Since your DLL project just upgraded to VS2005, is it possible that the new ... buffer and the return address. ... it will have to overwrite the cookie put in between it and the ...
    (microsoft.public.vc.ide_general)
  • Re: C++ to read cookies created by local HTML file
    ... BOOL bReturn; ... // Create a persistent cookie. ... // buffer size needed to download the cookie data. ... I tried to retrieve the cookies which are created ...
    (microsoft.public.vc.mfc)
  • Re: C++ to read cookies created by local HTML file
    ... BOOL bReturn; ... // Create a persistent cookie. ... // buffer size needed to download the cookie data. ... I tried to retrieve the cookies which are created ...
    (microsoft.public.vc.mfc)
  • Re: calling external php file before <html> tag
    ... The first command ... will cause PHP to buffer the output until the second command is ... This also means you don't need to put your cookie function ... before the but it is a good idea to execute it as soon as you ...
    (comp.lang.php)
  • Re: calling external php file before <html> tag
    ... The first command ... will cause PHP to buffer the output until the second command is ... This also means you don't need to put your cookie function ... before the but it is a good idea to execute it as soon as you ...
    (alt.php)