Login Script Problems

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!

Moderator: General Moderators

Post Reply
Kaoru
Forum Newbie
Posts: 3
Joined: Mon Feb 04, 2008 12:50 pm

Login Script Problems

Post 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]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Login Script Problems

Post 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.
Kaoru
Forum Newbie
Posts: 3
Joined: Mon Feb 04, 2008 12:50 pm

Re: Login Script Problems

Post 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
sastha
Forum Newbie
Posts: 6
Joined: Tue Feb 05, 2008 3:42 am

Re: Login Script Problems

Post 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..
Kaoru
Forum Newbie
Posts: 3
Joined: Mon Feb 04, 2008 12:50 pm

Re: Login Script Problems

Post 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.
Post Reply