View Full Version : [PHP] Help Please?
ThisNameWillDo!
05-12-2009, 11:56 AM
Hey, basically I have got a simple login script, but if I put any html above the PHP or I include the login page on another page, it comes up with the following error and it won't log me in:
Warning: Cannot modify header information - headers already sent by (output started at IREMOVEDTHIS/index.php:12) in IREMOVEDTHIS/login.php on line 28
Warning: Cannot modify header information - headers already sent by (output started at IREMOVEDTHIS/index.php:12) in IREMOVEDTHIS/login.php on line 29
Any idea how I can stop this? +Rep to any help :)
Thanks,
Vince.
All uses of header in php must be before anything is output to the client.
ThisNameWillDo!
05-12-2009, 12:46 PM
Thanks, but the lines that are causing the error are:
setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");
I don't see how I can put this before where it is, because it happens when the user is logged in and needs to be where it is, is there any way I can change it so it doesn't cause that error?
It sets cookies, which requires headers being sent. Just put whatever html you want after the PHP. I can't really help futher unless you post the whole file as I don't see why it should be a problem to add your HTML after the PHP.
ThisNameWillDo!
05-12-2009, 06:41 PM
It sets cookies, which requires headers being sent. Just put whatever html you want after the PHP. I can't really help futher unless you post the whole file as I don't see why it should be a problem to add your HTML after the PHP.
Okay thanks, I really appreciate your help :) In attempt to resolve this, I just put everything on the index file in PHP echo so that there's no HTML above any PHP, but now I can't get it to include files by doing <? include 'login.php'; ?> because it's all in echo ""; arghhh, is there any way i can get it to include a file when it's inside an echo :S
Invent
05-12-2009, 09:14 PM
Okay thanks, I really appreciate your help :) In attempt to resolve this, I just put everything on the index file in PHP echo so that there's no HTML above any PHP, but now I can't get it to include files by doing <? include 'login.php'; ?> because it's all in echo ""; arghhh, is there any way i can get it to include a file when it's inside an echo :S
Why can't you just end the echo, include the file and then re-start it?..
ThisNameWillDo!
06-12-2009, 12:49 AM
Agh thanks but it still comes up with that damn headers error, is there no way around this? :S
As I've said before, without the full code it is going to be difficult to help you.
Protege
06-12-2009, 08:06 AM
Agh thanks but it still comes up with that damn headers error, is there no way around this? :S
Well if you listen to what people have said, you would understand that you cant have any function placed after any data is sent to the browser (for example: HTML)
So setcookie, header, functions arent going to work and are going to throw a error (or a paddy)
So inorder to by pass this, any data you wish to send needs to be after the function is initiated.
Code #1
<?php
setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");
echo 'Cookies set';
?>
Code #2
<?php
echo 'Setting cookies';
setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");
?>
Code #3
<?php
include 'loads_of_html.html';
setcookie("id", $user[id],time()+(60*60*24*5), "/", "");
setcookie("pass", $user[password],time()+(60*60*24*5), "/", "");
echo 'Cookies set';
?>
Just so we're on the right lines, which ones do you think will work? (Without testing it)
ThisNameWillDo!
06-12-2009, 12:52 PM
I've sorted the problem now, thank you all for your help! I'll +rep you all if I can.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.