I have this php login system, I had it working great on localhost, I bought a webhotel and now it doesn’t work no longer, and i can’t find where it goes wrong.
I get no errors.
The login page is in index.php, and when you sign in, and if everythings ok (no errors/wrong pw etc.) then you will be redirected to home.php.
This is not the case. When I log in, it just refreshes the index.php and outputs this at top:
Warning: Cannot modify header information – headers already sent by (httpd.www/oBz/index.php:2) in httpd.www/oBz/index.php on line 221
on line 221 there’s:
header(“Location: home.php”);
ok, so i went to home.php manually by enter in the address. Now in home.php I have this at top:
include 'dbc.php';
page_protect();
echo "HELLO WORLD";
page_protect checks if there’s any sessions set or cookie(remember me), but if something has been set you will see the content “HELLO WORLD” else you wont.
But right now when i enter home.php I just receive this:
Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at httpd.www/oBz/dbc.php:29) in httpd.www/oBz/dbc.php on line 69
Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at httpd.www/oBz/dbc.php:29) in httpd.www/oBz/dbc.php on line 69
Warning: Cannot modify header information – headers already sent by (output started at httpd.www/oBz/dbc.php:29) in httpd.www/oBz/dbc.php on line 117
Line 69 theres session_start(), and it’s the first line in the function page_protect();
line 117 theres header("Location: index.php") and is there to redirect if you are not logged in(session set/cookie set)
Hope i provided information enough, if not just comment what you need, and i’ll try my best to provide it to you..
Thank you
Update:
Here is dbc.php: http://phpbin.net/x/999009567
**index.php where you log in and where the session sets http://phpbin.net/x/1564167411
**UPDATE:
I now solved the header warning/errors but that was not the solution for the session issue!
**UPDATE:
phpbin.net/x/25857430 the updated dbc.php, all the html that was in the dbc.php previously is in a new file top.php. I include the top.php file AFTER the doLogin function section in index.php, so there doesnt get any errors with the headers..
***UPDATE: The problem is somewhere here: http://phpbin.net/x/557713701 thats why its redirecting me to index.php all the time
You’ve already sent output to the browser with all that HTML that exists before your first bit of PHP.
You need to rearrange the code, so that anything which needs to send headers happens before any HTML is sent to the browser.
So:
The simplest answer may be to move all of that HTML after the PHP code. There’s a
session_regenerate_id()call in there and anothersession_start()in thelogoutfunction.For that matter, why do have any HTML in this file anyway? Beyond the session functions, I spotted at least 2
header()calls.Update:
So, if the cookie values don’t exist, what do you suppose happens here?