SOLVED - Session or Cookie?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

Post by johnperkins21 »

Dave, I tried your idea and got the following error:

PHP Warning: Cannot add header information - headers already sent by (output started at /tenyardfight/testcookie.php:3) in /tenyardfight/testcookie.php on line 4

I don't see how there are any headers being sent? I copied your code exactly as a test.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

johnperkins21 wrote:Dave, I tried your idea and got the following error:

PHP Warning: Cannot add header information - headers already sent by (output started at /tenyardfight/testcookie.php:3) in /tenyardfight/testcookie.php on line 4

I don't see how there are any headers being sent? I copied your code exactly as a test.
Duh, sorry John. Geesh, I need another coffee this morning.

Take out all the HTML before the <?php, so <?php is the first thing in the file.

(The cookies are sent in the header, but I had you output html code which goes AFTER the headers.)
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

Post by johnperkins21 »

Yeah, I changed that part. Still not working.

Got rid of the error, but still not setting the cookie. Strange.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

johnperkins21 wrote: still not setting the cookie. Strange.
Try cutting out some of the optional stuff. I think all that's mandatory is the name and the value. Does this work?

Code: Select all

<?php
  setcookie("MyName", "MyValue");
?>
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

Post by johnperkins21 »

Neato,
I got the cookie from your example to work by working my way back and adding each value one at a time. Then I took that code and copied it into my setcookie.php with no cookie being set and no error. Bummer. I'll keep working on it, but I appreciate you helping me with this.
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

Post by johnperkins21 »

Dude, I played with it for about an hour or so, and I finally got it working.

I need to pass the variable to a separate page that just sets the cookie, but it seems to be working. Thanks for the help Dave.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

johnperkins21 wrote:Dude, I played with it for about an hour or so, and I finally got it working.
That's great, congrats!

[rant]
"So, how long will it take," asks the Boss. How do you estimate time acurately when it takes two days to put down a cookie! It's the dumb little stuff that eats up development time.
[/rant]
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

isn't it funny how fixing a coding problem can easily steal hours away from the day. last night i spent about hour and 40 so mins working on a script that dealt with the dreaded regular expressions.

:roll:
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

Post by johnperkins21 »

And it almost always turns out to be something either easy or stupid. At least on my part, but I'm kind of dumb.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

johnperkins21 wrote:I'm kind of dumb.
smart enough to solve your own problems.. most people just want to use this board to have the others code for them.
johnperkins21 wrote:And it almost always turns out to be something either easy or stupid
Yeah, a forgotten ";" a ) missing. Its those mistakes that make u a stronger coder when your in notepad(or whatever you use to code in) typing away. you'll see you'll make less n less as you learn more n more!

[/uncle_tom_talk]
Post Reply