Results 1 to 16 of 16

Thread: Cookies (Again)

  1. #1

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Unhappy Cookies (Again)

    Hi!

    I searched the forum for this but coudn't find anything. I want to know why this code isn't working:

    Code:
    <?php
    setcookie('log', ' ', time()-60);	
    include("functions.php");
    echo "Wait...";
    redirect('login.php'); 
    ?>
    That's the only thing in the file. That file is called 'logout.php' and from a javascript function I'm doing a:

    Code:
    window.location.replace('logout.php');
    It is suppose to clear the cookie but I'm getting the following error:

    Warning: Cannot modify header information - headers already sent by

    Any ideas?
    The biggest man you ever did see was once just a baby.

    Bob Marley

  2. #2
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Cookies (Again)

    redirect() function will more than likely send a header:
    PHP Code:
    header("Location: $file"); // = header("Location: login.php"); 
    If you remove
    PHP Code:
    echo "Wait..."
    it should work.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  3. #3

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Re: Cookies (Again)

    I don't get it. Replace my current redirect function with this one? 'Cause if I remove the echo still doesn't work...

    This is my redirect function:

    Code:
        function redirect($url) { 
        die('<meta http-equiv="refresh" content="0;URL='.$url.'">'); 
        }
    Last edited by _Yoyo; May 29th, 2008 at 04:09 PM.
    The biggest man you ever did see was once just a baby.

    Bob Marley

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Cookies (Again)

    you need to make sure there isnt anything being echoed or a header before the setcookie()
    My usual boring signature: Something

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Cookies (Again)

    Quote Originally Posted by _Yoyo
    I don't get it. Replace my current redirect function with this one? 'Cause if I remove the echo still doesn't work...

    This is my redirect function:

    Code:
        function redirect($url) { 
        die('<meta http-equiv="refresh" content="0;URL='.$url.'">'); 
        }
    Whitespace such as tabs spaces and newlines at the top of the script and any included files also count as output.

    It is better to use a location header to redirect the request and send a Location header or the refresh header if you want a time out. This will prevent HTML level blocking of the action and ensure everything from browser to search engine indexers follow them.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Cookies (Again)

    Also, I recommend that you use a POST request to effect the logout. GET requests can be made at any time and should have no adverse side-effects.

  7. #7

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Re: Cookies (Again)

    Quote Originally Posted by visualAd
    Whitespace such as tabs spaces and newlines at the top of the script and any included files also count as output.

    It is better to use a location header to redirect the request and send a Location header or the refresh header if you want a time out. This will prevent HTML level blocking of the action and ensure everything from browser to search engine indexers follow them.
    As you can see, the script uses the setcookie right after the php tag so there's no spaces or tab or echoes whatsoever. Anyways, I replaced the redirect function, forced a POST and still nothing.
    The biggest man you ever did see was once just a baby.

    Bob Marley

  8. #8
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Cookies (Again)

    What is after this??

    "Warning: Cannot modify header information - headers already sent by"... ?
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Cookies (Again)

    Attach the file to a post. Sometimes PHP can be finicky with character sets and the like and it is very hard to debug without seeing the whole script file.

  10. #10

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Re: Cookies (Again)

    Quote Originally Posted by RudiVisser
    What is after this??

    "Warning: Cannot modify header information - headers already sent by"... ?

    Cannot modify header information - headers already sent by (output started at /usr/local/www/data/segti/logout.php:1) in /usr/local/www/data/segti/logout.php on line 2
    The biggest man you ever did see was once just a baby.

    Bob Marley

  11. #11

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Re: Cookies (Again)

    Quote Originally Posted by penagate
    Attach the file to a post. Sometimes PHP can be finicky with character sets and the like and it is very hard to debug without seeing the whole script file.
    You mean this one, right?
    Attached Files Attached Files
    The biggest man you ever did see was once just a baby.

    Bob Marley

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Cookies (Again)

    Try this. Let me know if it works or doesn't work.
    Attached Files Attached Files

  13. #13
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Cookies (Again)

    Quote Originally Posted by _Yoyo
    You mean this one, right?
    The file has preceding unicode characters. If you are editing the file in notepad make sure you have saved the file in ASCII rather than Unicode.

    Hex view:
    Code:
    0000000: efbb bf3c 3f70 6870 0d0a 7365 7463 6f6f  ...<?php..setcoo
    0000010: 6b69 6528 276c 6f67 272c 2027 2027 2c20  kie('log', ' ',
    Edit: BTW, the preceding characters are known as a Unicode BOM (Byte order mark) it tells text editors the encoding used in the file.
    Last edited by visualAd; May 30th, 2008 at 08:27 AM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  14. #14
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Cookies (Again)

    yeah, I converted it to ANSI. I was trying to be subtle.

    PHP doesn't interpret the BOM; rather, it treats it as output, hence why it breaks headers.
    I believe version 6 fixes this.

  15. #15
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Cookies (Again)

    Quote Originally Posted by penagate
    yeah, I converted it to ANSI. I was trying to be subtle.

    PHP doesn't interpret the BOM; rather, it treats it as output, hence why it breaks headers.
    I believe version 6 fixes this.
    I was tripped up by that once as well.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  16. #16

    Thread Starter
    Addicted Member _Yoyo's Avatar
    Join Date
    Apr 2001
    Location
    Dominican Republic
    Posts
    187

    Re: Cookies (Again)

    The error is gone!!!! But the cookie is still there

    BTW, is this a good way to "erase" a cookie?
    The biggest man you ever did see was once just a baby.

    Bob Marley

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width