Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-13-2006, 07:51 AM   #1
Registered: Oct 2005
Location: China
Distribution: ArchLinux
Posts: 103

Rep: Reputation: 15
a simple problem about cookie(PHP)

I know, the "setcookie()" must be front of every action in PHP.
But, I know lots of web is comparing the user and pass with the database record first and "setcookie()" as follow.

How to do this?
Old 03-13-2006, 08:47 AM   #2
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,296

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335

SetCookie must be used before any output the script makes, not before every action.

So it's really not that hard.
Old 03-13-2006, 11:36 AM   #3
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
You must handle your cookies before anything is output to browser (including PHP error/notice messages)... before the headers are sent out. One way to ensure this is to use output buffering:

// whatever your code is to check db and information, 
// validation, etc.  Just dont' do anything that outputs 
// anything just yet
setcookie(); // whatever

// now you can output 

ob_flush(); // flush buffer


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple problem about php mohtasham1983 Programming 6 01-05-2006 09:09 PM
php mcrypt cookie - mysql query lemack Linux - Security 3 02-09-2005 09:21 AM
PHP code did not create a cookie and it did not changed the background and text color Linh Programming 5 07-29-2004 10:15 PM
url redirection/cookie problem tuxrules Linux - Newbie 3 07-13-2004 06:23 AM
Cookie Problem in IE Doovie Programming 0 07-08-2003 08:47 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:07 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration