Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Login doesn't work

    As the title says, my login doesn't work i can login with each password their not hashed maybe in the future i will

    PHP Code:
    //login.php
    <form method=post action=logprocess.php>
    Username:<input type=text name=usernameftw><br>
    Password:<input type=password name=passwordftw><br>
        <input type=submit value='Login.'><input type=reset value='Reset.'>

    // logprocess.php
    <? session_start();
    $_SESSION['logged'] = 0;
    $name $_POST['usernameftw'];
    $pass $_POST['passwordftw'];
    if(
    $name == "" and $pass == "")
    {
        
    Header ("Location: login.php?error=3");
    }
    if(
    $name == "")
    {
        
    Header ("Location: login.php?error=1");
    }
    if(
    $pass == "")
    {
        
    Header ("Location: login.php?error=2");
    }
    mysql_connect("localhost""root""password")
        or die(
    "Could not connect to database");
    mysql_select_db("database") or die("Could not select database");
    $sql mysql_query("SELECT * FROM accounts WHERE name='$name'");
    if(!
    $sql)
    {
        
    Header ("Location: login.php?error=4");
    }
    while(
    $a mysql_fetch_array($sql))
    {
        if(
    $pass != $a['password'])
        {
            
    Header ("Location: login.php?error=5");
        }
        
    $_SESSION['logid'] = $a['user_id'];
    }
    $_SESSION['logged'] = 1;
    Header ("Location: mindex.php");
    ?>

  • #2
    New Coder
    Join Date
    Jan 2009
    Posts
    91
    Thanks
    17
    Thanked 1 Time in 1 Post
    I assume this is supposed to be mindex?

    PHP Code:
    $_SESSION['logged'] = 1
    Header ("Location: mindex.php"); 

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Hayyel View Post
    I assume this is supposed to be mindex?

    PHP Code:
    $_SESSION['logged'] = 1
    Header ("Location: mindex.php"); 
    mindex.php is just a page that shows Welcome to members area, if you not logged in it says please login

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    As the title says, my login doesn't work i can login with each password their not hashed maybe in the future i will
    Are you getting any error? If not, add
    PHP Code:
    <?php
    ini_set
    ('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting (E_ALL);
    ?>
    at the top of your page. Also, it's a good idea to have an error free markup while debugging something. Validate your markup using http://validator.w3.org/#validate_by_input
    Last edited by abduraooft; 05-05-2009 at 12:02 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Mar 2009
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Are you getting any error? If not, add
    PHP Code:
    <?php
    ini_set
    ('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting (E_ALL);
    ?>
    at the top of your page.
    i dind't get errors, but i will get errors if i do something wrong, i just have the problem that if my password = 'sheep' i can login with 'goat' and 'sheep' and every word i put in..

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    PHP Code:
    while($a mysql_fetch_array($sql))
    {
        if(
    $pass != $a['password'])
        {
            
    Header ("Location: login.php?error=5");
        }
        
    $_SESSION['logid'] = $a['user_id'];
    }
    $_SESSION['logged'] = 1;
    Header ("Location: mindex.php"); 
    try the following instead
    PHP Code:
    $a mysql_fetch_array($sql);

        if(
    $pass != $a['password'])
        {
            
    Header ("Location: login.php?error=5");
        }
        else{
        
    $_SESSION['logid'] = $a['user_id'];
        
    $_SESSION['logged'] = 1;
        
    Header ("Location: mindex.php"); 

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Pandabeer (05-05-2009)

  • #7
    New Coder
    Join Date
    Mar 2009
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    try the following instead
    PHP Code:
    $a mysql_fetch_array($sql);

        if(
    $pass != $a['password'])
        {
            
    Header ("Location: login.php?error=5");
        }
        else{
        
    $_SESSION['logid'] = $a['user_id'];
        
    $_SESSION['logged'] = 1;
        
    Header ("Location: mindex.php"); 

    thanks for that, but now even if i fill in the right password, it says Password is incorrect! (login.php?error=5)

    PHP Code:
    if($pass != $a['password'])
    {
        
    Header ("Location: login.php?error=5");

    PHP Code:
    // whole shizzel
    session_start();
    $_SESSION['logged'] = 0;
    $name $_POST['usernameftw'];
    $pass $_POST['passwordftw'];
    if(
    $name == "" and $pass == "")
    {
        
    Header ("Location: login.php?error=3");
    }
    if(
    $name == "")
    {
        
    Header ("Location: login.php?error=1");
    }
    if(
    $pass == "")
    {
        
    Header ("Location: login.php?error=2");
    }
    mysql_connect("localhost""root""password")
        or die(
    "Could not connect to database");
    mysql_select_db("database") or die("Could not select database");
    $sql mysql_query("SELECT * FROM accounts WHERE name='$name'");
    if(!
    $sql)
    {
        
    Header ("Location: login.php?error=4");
    }
    $a mysql_fetch_array($sql);

    if(
    $pass != $a['password'])
    {
        
    Header ("Location: login.php?error=5");
    }
    else{
    $_SESSION['logid'] = $a['user_id'];
    $_SESSION['logged'] = 1;
    Header ("Location: mindex.php"); 


  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Are you really getting the required values from your DB? Put some echo/print_r statements to debug your code at intermediate steps, say
    PHP Code:
    $a mysql_fetch_array($sql); 
    echo 
    '<pre>';print_r($a);echo '</pre>'
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    New Coder
    Join Date
    Jan 2009
    Posts
    91
    Thanks
    17
    Thanked 1 Time in 1 Post
    Can you post your form please.

  • #10
    New Coder
    Join Date
    Mar 2009
    Posts
    43
    Thanks
    2
    Thanked 0 Times in 0 Posts
    PHP Code:
    <form method=post action=logprocess.php>
    Username:<input type=text name=usernameftw><br>
    Password:<input type=password name=passwordftw><br>
        <
    input type=submit value='Login.'><input type=reset value='Reset.'

    but if i print these things, itll work the problem is he wont get anything from the database.


    Quote Originally Posted by abduraooft View Post
    Are you really getting the required values from your DB? Put some echo/print_r statements to debug your code at intermediate steps, say
    PHP Code:
    $a mysql_fetch_array($sql); 
    echo 
    '<pre>';print_r($a);echo '</pre>'
    well i did this but it wouldnt show anything.
    Last edited by Pandabeer; 05-10-2009 at 11:18 AM. Reason: INFO! :D

  • #11
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Try
    PHP Code:
    $sql mysql_query("SELECT * FROM accounts WHERE name='$name'") or die(mysql_error()); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •