LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-13-2006, 08:51 AM   #1
naihe2010
Member
 
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, 09:47 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,295

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

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, 12:36 PM   #3
MicahCarrick
Member
 
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:
Code:
ob_start();

// 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
 
  


Reply


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 10:09 PM
php mcrypt cookie - mysql query lemack Linux - Security 3 02-09-2005 10: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 11:15 PM
url redirection/cookie problem tuxrules Linux - Newbie 3 07-13-2004 07:23 AM
Cookie Problem in IE Doovie Programming 0 07-08-2003 09:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:23 PM.

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