Page 1 of 2 12 LastLast
Results 1 to 40 of 52

Thread: Cookies

  1. #1

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Angry Cookies

    Warning: Cannot add header information - headers already sent by (output started at /home/tom/sviesoft/login/login.php:8) in /home/tom/sviesoft/login/login.php on line 1000099238

    what is wrong?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  2. #2
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    youre probably new to this whole cookie deal

    the reason you probably got that error is because you have already written some output data. you have to set a cookie before any " ECHO ''; " or crap like that. did this help ?

  3. #3
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    To sum up what ubunreal69 said a bit clearer..

    A cookie has to be set before any output of any kind is made. This includes html, javascript, php echo or print statements, etc.

    Example (these will not work):
    PHP Code:
    <html>
    <?php setcookie("","","","",""); ?>
    PHP Code:
    <?php
      
    echo "Text";
      
    setcookie("","","","","");
    ?>
    Example (these will work):
    PHP Code:
    <?php setcookie("","","","",""); ?>
    <html>
    PHP Code:
    <?php
      setcookie
    ("","","","","");
      echo 
    "Text";
    ?>
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  4. #4
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    How would you see if a cookie existed?

  5. #5
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: Cookies

    Originally posted by prog_tom
    Warning: Cannot add header information - headers already sent by (output started at /home/tom/sviesoft/login/login.php:8) in /home/tom/sviesoft/login/login.php on line 1000099238

    what is wrong?
    show us the code?

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Originally posted by Gimlin
    How would you see if a cookie existed?
    PHP Code:
    if (isset($_COOKIE['variable name']))
      echo 
    "The cookie exists with the value of ".$_COOKIE['variable name'];
    else
      echo 
    "The cookie does not exist." 
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    thanks

  8. #8

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    I tried:

    PHP Code:
    <?setcookie("myage","12",time()+600);print "$myage";?>
    doesn't work.

    you may view this file at
    http://www.sviesoft.com/beta/cookie.php

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  9. #9
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    you should always set as the path and domain portions of the cookie.

    PHP Code:
    <?php
     setcookie
    ("myage","12",time()+600,"/",$_SERVER['HTTP_HOST']);
     if (!isset(
    $_COOKIE['myage']))
      echo 
    "Please Refresh the page.";
     else
      echo 
    $_COOKIE['myage'];
    ?>
    Viewable at http://cpradio.net/cookieTest.php
    Source Code: http://cpradio.net/cookieTest.phps
    Last edited by cpradio; Jul 29th, 2002 at 10:18 AM.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by prog_tom
    I tried:

    PHP Code:
    <?setcookie("myage","12",time()+600);print "$myage";?>
    doesn't work.

    you may view this file at
    http://www.sviesoft.com/beta/cookie.php
    we need to see the whole page.

  11. #11
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Originally posted by phpman

    we need to see the whole page.
    No we don't
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by prog_tom
    I tried:

    PHP Code:
    <?setcookie("myage","12",time()+600);print "$myage";?>
    Just a few quick notes:
    • According to standards, you should always use "<?php" instead of "<?" You should also never put more than one statement on one line.
    • Cookies should be displayed as "$_COOKIE["myage"]" for 4.2 compatability.
    • And finally: "Cookies will not become visible until the next loading of a page that the cookie should be visible for." So printing "$myage" would not work until you refreshed.


    Matt already covered most of these, but I thought I'd buzz in anyways.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by cpradio


    No we don't
    well I thought he was still getting the error.

    but it seems that you have taken care of Tom.

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman

    well I thought he was still getting the error.

    but it seems that you have taken care of Tom.
    It's a very common error, that's why we didn't need to see code.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    really, so where was the error?

    and tell me if this will produce a header error

    PHP Code:
    <?php
      $var 
    "hello";
    ?>


    <?php
      setcookie
    ("","","","","");
    ?>
    that is one file by the way.

  16. #16
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    I love the redundant questions in life
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  17. #17
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Originally posted by phpman
    really, so where was the error?

    and tell me if this will produce a header error

    PHP Code:
    <?php
      $var 
    "hello";
    ?>


    <?php
      setcookie
    ("","","","","");
    ?>
    that is one file by the way.
    This will produce an error, as white space has been created above the setcookie function. PHP only ignores white space inbetween the <?php ?> tagsand this white space was created by the file/html/whatever. (sounds redundant doesn't it )

    Now you can use either of the below instead of what is written above:
    PHP Code:
    <?php
      $var 
    "hello";
    ?>
    <?php
      setcookie
    ("","","","","");
    ?>
    PHP Code:
    <?php
      $var 
    "hello";







      
    setcookie("","","","","");
    ?>
    Last edited by cpradio; Jul 29th, 2002 at 12:10 PM.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  18. #18
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    yes, you are correct Matt, but I was just curious as to how you knew it was something being echoed or just white space. if he was new to this then he would say there is nothing that is being echoed. but it seems that he was talking to somebody behind the scences.

    yes it would produce an error and no newbie would now that.

    even if he included a file before the setcookie like the code I gave it would produce the same error. that is why I said to show us the code.

    in /home/tom/sviesoft/login/login.php on line 1000099238
    100009238+ lines of code?????????? yeah right. I never seen file with that many lines of code.

  19. #19
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    point made
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  20. #20
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I just thought it'd be easier to tell him what was up, then have him post code and point out the individual mistakes.

    And just incase anyone cares, it's raining all around my house except in my back yard. Imma go watch it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  21. #21

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    100009238+ lines of code?????????? yeah right. I never seen file with that many lines of code.
    That's because most low-level never seen it. Thus you may be one of them.

    this cookie **** is driving me insane.


    check out:
    http://www.sviesoft.com/beta/1.php

    PHP Code:
    <?setcookie("yonghuming","prog_tom",NULL,"","sviesoft.com");
    if(isset($yonghuming)){print $yonghuming;}?>
    everytime I make expiration to time()+600, it just doesn't work, seems like PHP on my server either didn't set up correctly, or it doesn't support time(). It doesn't support $_COOKIES or other crap either, if I use $_COOKIES it gives me $T_VAR or some crap error.

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  22. #22
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    That's because most low-level never seen it. Thus you may be one of them.
    bull**** Tom, don't give me that. even professional programmers don't have pages that long. and you call yourself a high-level programmer? you can't even get a cookie right......

    I can almost bet you didn't write it either. let me see the file if it has that many lines in it.....


    <?
    setcookie("yonghuming","prog_tom", time() +600,"","sviesoft.com");
    if(isset($yonghuming)){print $yonghuming;}?>

  23. #23

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    Did I mention anything as a programmer myself? I wish, someday, to become one, but first I gotta learn from you.
    PHP Code:
    setcookie("yonghuming","prog_tom",0,"/","",0); 
    that seems working, but how long do 0 last? forever?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  24. #24
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    no cookie can last forever. al you can do is make it last a year I think.

    I think if you set it at 0 then it will go away when the browser is closed.

    just set time() +43200

    setcookie("yonghuming","prog_tom", time() +43200 );

  25. #25
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    no cookie can last forever. al you can do is make it last a year I think.

    I think if you set it at 0 then it will go away when the browser is closed.

    just set time() +43200

    setcookie("yonghuming","prog_tom", time() +43200 );
    Yeah, cookies always expire, although I think you can make them longer than a year. And yes, it'll expire when the browser closes if it's set to 0.

    My suggestion: set it for a year and renew it each time the user comes to the page.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  26. #26
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman

    bull**** Tom, don't give me that. even professional programmers don't have pages that long.
    I have to agree there. 100 million lines (100,009,238) of code is way, way beyond absurd...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  27. #27

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    the file is nearly 1.3 TB.

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  28. #28
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    yeah and my dick is 5 miles long,

    give me a break Tom

  29. #29
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by prog_tom
    the file is nearly 1.3 TB.
    hmm...how do you fit that on a 120 gig hard drive?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  30. #30
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    Yah? and what does it do Tom

  31. #31
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Cookies

    Originally posted by prog_tom
    Warning: Cannot add header information - headers already sent by (output started at /home/tom/sviesoft/login/login.php:8) in /home/tom/sviesoft/login/login.php on line 1000099238

    what is wrong?
    hmmm...does tommy lie alot?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  32. #32
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    prog_tom, are you sure the server even supports cookies ? try a simple bit of code to just test it first.

    simple test:
    PHP Code:
    setcookie("greeting","elooo"time()+3600);
    IF (isset(
    $_COOKIE['greeting']))
    {ECHO 
    'cookie value is'$_COOKIE['greeting'];} 

  33. #33
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734

    Re: Re: Cookies

    Originally posted by The Hobo


    hmmm...does tommy lie alot?
    Good catch

  34. #34
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by ubunreal69
    prog_tom, are you sure the server even supports cookies ? try a simple bit of code to just test it first.

    simple test:
    PHP Code:
    setcookie("greeting","elooo"time()+3600);
    IF (isset(
    $_COOKIE['greeting']))
    {ECHO 
    'cookie value is'$_COOKIE['greeting'];} 
    That won't work. Cookies aren't accessable until it is reloaded. Cookies won't appear until the script that set them is refreshed.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  35. #35
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    Originally posted by The Hobo
    That won't work. Cookies aren't accessable until it is reloaded. Cookies won't appear until the script that set them is refreshed.
    let me re-phrase it then

    put:
    PHP Code:
    setcookie("greeting","elooo"time()+3600);
    IF (isset(
    $_COOKIE['greeting']))
    {ECHO 
    'cookie value is'$_COOKIE['greeting'];} 
    run the page, then refresh it.



  36. #36
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    A new line for each statement?!

    Yo! My first post...

    Er, don't mean to critiscise anyone, but who cares about not putting each statement on a new line?!

    I certaintly don't - that's what the ";" closing character is for!!!

    And jeez, all that unnecessary whitespace! Pah...

    You can make pages verbose, without using stupid format conventions that take up space! After all, why format the formatting code...? (such as HTML - but applies to PHP,VBScript,Javascript, etc.)

    P.S: A 1.3+ Terrabyte script?! I wonder how long that imaginary file would take to execute on the server... lol yeah, right...
    Last edited by trojjer; Jul 31st, 2002 at 06:13 PM.
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  37. #37
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: A new line for each statement?!

    Originally posted by trojjer
    Er, don't mean to critiscise anyone, but who cares about not putting each statement on a new line?!
    Employers? I know people who have been told they didn't get the job because of things like that. The employer looks at your work and see's a confusing mess, he's going to hand you a candy cane and tell you to go home.

    So if you every want a job, you should care. If you're just going to make piss-ass programs for the rest of your life, feel free.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  38. #38
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: A new line for each statement?!

    Originally posted by trojjer
    Yo! My first post...

    Er, don't mean to critiscise anyone, but who cares about not putting each statement on a new line?!

    I certaintly don't - that's what the ";" closing character is for!!!

    And jeez, all that unnecessary whitespace! Pah...

    You can make pages verbose, without using stupid format conventions that take up space! After all, why format the formatting code...? (such as HTML - but applies to PHP,VBScript,Javascript, etc.)
    dude I don't believe you just said that. I would hate to see your code.

    fjdksa fl;sdlthisjg dfksajf dkisdfjska l;fjd sakl;onej gdsfkalf;jdksla ;longfj dskalfj;d skal;linefjdksafj dskla;

    can you tell what that line just said? no I bet you can't, give me a break will ya. it's only human to make it so it is readable.

    suppose you made that 1.3 TB file for Tom huh?

  39. #39
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296
    That script would take more than 24 hours to lead from a server, It'll probablt make the server crash with that many lines and we all know you're lieing so shut the **** up and leard how to set a cookie!!! END OF DISCUSSION!, PS. You're a retard
    Kevin Carpenter
    Currently Working in the CAOS (CA Operating System) Group

  40. #40

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    heh, it worked

    wow, 5 miles. we can walk on it.
    i love to write code in one line or 2 with no spaces, ; between them, that way, no one would peek it.

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

Page 1 of 2 12 LastLast

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