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!
Hello, i have a slight problem in my code, and i do not know how to resolve it. Can anyone help?
Warning: Cannot add header information - headers already sent by (output started at C:\www\Apache\htdocs\inc\functions.lib.php:869) in c:\www\apache\htdocs\login.php on line 30
Warning: Cannot add header information - headers already sent by (output started at C:\www\Apache\htdocs\inc\functions.lib.php:869) in c:\www\apache\htdocs\login.php on line 31
Warning: Cannot add header information - headers already sent by (output started at C:\www\Apache\htdocs\inc\functions.lib.php:869) in c:\www\apache\htdocs\login.php on line 32
That's what i get from login.php which looks like this:
Yes SetCookies is a real fussy little bitch that is useless for anything that needs security.
Because you need to put the setcookie first it basically has to go at the top of the script. So anyone can come along pass a variable to your script and login.
rats: That has nothing to do with cookies, and everything to do with not knowing how to code properly. It is very easy to use cookies and prevent what you describe.
Just in case you haven't soved the problem yet:
Mike from schottland was quite right: setcookie() and header() are functions that have to be called before any output ist generated. the typical mistake in this case is that you have a whitespace or carriage return character in your code (which you can anly see in a good editor). It is very likely that this mistake happened in functions.lib.php at line 869 (look a little closer).
jason wrote:rats: That has nothing to do with cookies, and everything to do with not knowing how to code properly. It is very easy to use cookies and prevent what you describe.
haha that error is exactly what I get from your site Jason (Login.php) whenever I try to login to NN.
Unless you have modified your apache settings you will probably want to drop the .inc extension and rename those files to .php or .inc.php. This will stop us from getting your database user name / password and actually seeing your code (not good).
Several people answered the question but rather quickly so let me detail a little further.
1. You have to send any header information before you send any cookie information. This is the biggest thing to get around when you start playing with sessions. I find that a lot of early PHP developers work themselves into a hole of sorts with how they are taught PHP. This can however be avoided with a good design methodology. For example, do all of your logical processing before you send output. Setup your includes and other pieces before you start getting into the core logic of your page. Try to achieve as much separation of logic and code as you can. With the right design you can achieve about 90-95%.
2. Output buffering - Lookup on the PHP.net site ob_start(); and read about this function. These set of functions will buffer the output before sending it down and "re-shift" the headers around for you before sending output thereby circumventing the problem of poor design. You can also use this set of functions to gzip your data before sending it down as well. A common trick to speed up downloads for users and speed up the server.
Ok, thanks alot for the pointers...I shall gather some more information on ob_start();
thanks.
zorka wrote:Unless you have modified your apache settings you will probably want to drop the .inc extension and rename those files to .php or .inc.php. This will stop us from getting your database user name / password and actually seeing your code (not good).
Several people answered the question but rather quickly so let me detail a little further.
1. You have to send any header information before you send any cookie information. This is the biggest thing to get around when you start playing with sessions. I find that a lot of early PHP developers work themselves into a hole of sorts with how they are taught PHP. This can however be avoided with a good design methodology. For example, do all of your logical processing before you send output. Setup your includes and other pieces before you start getting into the core logic of your page. Try to achieve as much separation of logic and code as you can. With the right design you can achieve about 90-95%.
2. Output buffering - Lookup on the PHP.net site ob_start(); and read about this function. These set of functions will buffer the output before sending it down and "re-shift" the headers around for you before sending output thereby circumventing the problem of poor design. You can also use this set of functions to gzip your data before sending it down as well. A common trick to speed up downloads for users and speed up the server.