+ 2

Login system not working when uploaded to server! But it was working good on localhost

I've the following login code for my site which was working until i was on local host but now I'm getting the following error Cannot modify header information - headers already sent by (output started at /home/uhostedm/public_html/ucinema.ml/admin/header.php:18) in /home/uhostedm/public_html/ucinema.ml/admin/login.phpon line 25 the Login Page Code Is https://code.sololearn.com/wIvBPBgZplH9/?ref=app and Here's The Header Code https://code.sololearn.com/wT8ONJfK5UN6/?ref=app How To Fix This?

5th Feb 2018, 7:59 PM
Vithul T Nair
Vithul T Nair - avatar
4 Respuestas
+ 2
As you can see by the error you posted, it's because you're trying to send/change header information after it's already been sent. In your login PHP file, move your PHP up above your HTML so it can execute first before the HTML (and its headers) does. You're trying to change the headers too late in the game. Try that out and let me know if it helped. If not, post up any new errors after you change that. This is a part of the reasoning behind why they say to keep HTML/CSS/JS/PHP/etc... separate from one another instead of mixing all of it together. Lot of little rules (and timing of actions) to play by, so you have to be careful with it. It's also good to look into the order that things get executed between HTML, PHP, and JS. PHP is happening on the server-side BEFORE everything else happens. It isn't happening in the order that you would think it does based upon the order that you wrote the code. Hope that helps!
5th Feb 2018, 8:31 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
Tried that aswell! but ran into more trouble! when i setup php in the top and html in the bottom I'm getting the following error.. Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in /home/uhostedm/public_html/ucinema.ml/admin/login.phpon line 7 Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in /home/uhostedm/public_html/ucinema.ml/admin/login.phpon line 9 Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/uhostedm/public_html/ucinema.ml/admin/login.phpon line 13
6th Feb 2018, 5:44 AM
Vithul T Nair
Vithul T Nair - avatar
6th Feb 2018, 6:07 AM
Vithul T Nair
Vithul T Nair - avatar
+ 1
Sorry, just seeing this. The problem is that it appears you're storing your database information in your header file, and since you're loading the header file after that code, it doesn't know what $conn means because it isn't defined at that point. If it were myself, I would create a session PHP file that you can store your "session_start()" and other database information/connection inside of. It would contain only PHP for that stuff and it wouldn't do anything at all with HTML headers. Then at the top of your login file, put your session.PHP (whatever you named it) include at the top before your MySQL code. This will allow your MySQL code to obtain the connection information and continue executing your PHP without messing with the HTML headers prior. Let me know if you're still having issues and I can help you out in realtime when I'm at home.
6th Feb 2018, 8:51 PM
Fata1 Err0r
Fata1 Err0r - avatar