Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-08-2008, 10:07 PM PHP Cookies
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
ok so I love cookies and all but these cookies never turn out right...

PHP Code:
setcookie("active""yes"time()+2592000);
setcookie("username"$_POST['username'], time()+2592000); 
I always get an error that the headers were already sent and so these cookies don't get saved
MoForce is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-09-2008, 12:20 AM Re: PHP Cookies
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
I just decided to use $_SESSION instead...
MoForce is offline
Reply With Quote
View Public Profile
 
Old 02-09-2008, 01:42 AM Re: PHP Cookies
kids's Avatar
Ultra Talker

Posts: 301
Trades: 0
Your problem is staying in IE only, is not right? If that's true, you can place
PHP Code:
header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'"); 
before setcookie

I have been got headache with setcookie, but when I place header("P3P..."), evthing's ok.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
kids is offline
Reply With Quote
View Public Profile Visit kids's homepage!
 
Old 02-09-2008, 07:26 AM Re: PHP Cookies
andyp's Avatar
Extreme Talker

Posts: 165
Name: andy patterson
Trades: 0
If you need a good tutorial for sessions i know a good one so post back if you want.
andyp is offline
Reply With Quote
View Public Profile
 
Old 02-09-2008, 08:16 AM Re: PHP Cookies
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
I always get an error that the headers were already sent
A cookie is passed in the page header.
This means that if any characters are outputed before, a cookie cannot be set.
You must set your cookies before you sent/echo any character to the browser.
And this include even a space, or carriage return, put before your php block.
http://www.php.net/manual/en/function.setcookie.php
Quote:
Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-09-2008, 10:46 AM Re: PHP Cookies
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Not really helpful but can i just ask why dont they make PHP so while its parsing the script it kind of "collects" any headers or header output through out the script, and then send that then what ever othe rout put the script makes?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-09-2008, 11:21 AM Re: PHP Cookies
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Er...
Dan, the output buffering functions are primarily designed for this...

http://www.php.net/manual/en/ref.outcontrol.php
Quote:
The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo() and data between blocks of PHP code.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-09-2008 at 11:23 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-09-2008, 11:49 AM Re: PHP Cookies
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
no i mean like automartically by the PHP parser.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-09-2008, 12:45 PM Re: PHP Cookies
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
well, different applications calls for choices.
They choosed to not force it's usage, and it makes sense to me, as any call to a function have a cost (I mean, ram, cpu and processing time).
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-09-2008, 03:44 PM Re: PHP Cookies
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I see okay i will shut up now sorry for butting in
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to PHP Cookies
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.11955 seconds with 12 queries