Page 1 of 1

Login Script Problems

Posted: Mon Feb 04, 2008 1:11 pm
by Kaoru
Script returns error:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at members.php line 1

Code: Select all

 
[b][u]LINE 1 of members.php:[/u][/b]
<?php session_start();?>

Code: Select all

 
[b][u]login.php[/u][/b]
<?php
    if (isset($_SESSION['login_auth'])) {
        header('Location: members.php');
    }
    if (isset($_POST) && count($_POST > 0) {
        $password = "password_here";
        if ($_POST[txtPass'] == $password) {
            $_SESSION['login_auth'] = "1";
            header('Location: members.php');
        } else {
            print "Incorrect password specified.";
        }
    } else {
        print "Error! No post vars found, please check <form> tags!";
    }
?>

Code: Select all

 
[b][u]Login form (index.html)[/u][/b]
<form id="frmLogin" action="login.php" method="post">
    <b>Password:</b> <input type="password" id="txtPass" name="txtPass" /><br /><br />
        <input id="btnLogin" type="submit" value="Log In" />
</form>
Everyone I've asked tells me there's a problem in the code, there's white space that's messing the thing up, but, in function the script works fine, there's no white space or problems with my code. The only issue is the afformentioned error that shows up on members.php after a successful login.
Also, it may not be a php issue, but when loaded from the internet server, the entire website is wrong, below is a url to a page that doesn't display properly, and a url to one that does. The only difference between these two pages is that the first one uses navigation scripts that aren't discussed here, while the second doesn't.
http://haven.astralwd.co.za - Bad
http://haven.astralwd.co.za/Access/oice%20Guide.html - Good

I've been sitting at a loss with these problems for nearly two months, so any suggestions will be greatly appreciated.[/color]

Re: Login Script Problems

Posted: Mon Feb 04, 2008 2:29 pm
by califdon
You need the session_start(); code in each script that does anything with a session. Add that to the top of your login.php.

Re: Login Script Problems

Posted: Tue Feb 05, 2008 12:55 am
by Kaoru
Did i forget to add it to my code? my bad. i fixed the problem last night though. like i said, no problems with the code, instead i saved login.php in ANSI encoding rather than UTF-8. all works fine now

Re: Login Script Problems

Posted: Tue Feb 05, 2008 7:03 am
by sastha
Comment this line:

$password = "password_here";

Save it and run it.

Dont try to display anything before redirection.You can make the script to wait for sometime before redirection.
Check it..

Re: Login Script Problems

Posted: Wed Feb 06, 2008 4:07 am
by Kaoru
Wouldn't commenting exclude it from the executed code? It makes no sense to me seeing as that's the line that determines whether or not the user actually has permission to access the protected pages. It does after all contain the correct password.