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 3 of 3

Thread: login issue

  1. #1
    Regular Coder
    Join Date
    Dec 2011
    Posts
    201
    Thanks
    12
    Thanked 26 Times in 26 Posts

    login issue

    been trying to debug for too long now, need to ask for some help.

    it all functions properly, except when I type in the verified correct login name and password. When I type in the correct info the redirect does not function, login.php is reloaded with a blank form and no errors?

    login.php
    PHP Code:
    if(isset($_POST['submit'])) {

      
    $username trim($_POST['username']);
      
    $password trim($_POST['password']);

      
    $found_user User::authenticate($username$password);
      
      if(
    $found_user) {
        
    $session->login($found_user);
        
    redirect_to("index.php");
      } else {
        
    $message "Username/password combination incorrect.";
      }
    } else {
      
    $username "";
      
    $password "";

    apart of my User class
    PHP Code:
    public static function authenticate($username=""$password="") {
       global 
    $database;
       
    $username $database->escape_value($username);
       
    $password $database->escape_value($password);
       
       
    $sql "SELECT * FROM users ";
       
    $sql .= "WHERE username = '{$username}' ";
       
    $sql .= "AND password = '{$password}' ";
       
    $sql .= "LIMIT 1"
       
    $result_array self::find_by_sql($sql);
       return !empty(
    $result_array) ? array_shift($result_array) : false;

     } 

  • #2
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    I don't have any way of testing my theory right now, but I think it could be the last major line in the second piece of code.

    PHP Code:
    return !empty($result_array) ? array_shift($result_array) : false
    This tells the script if the $result_array is not empty then return false.

    I would assume if the result returns as not empty then it would want to return true.

    Just a guess.

  • #3
    Regular Coder
    Join Date
    Dec 2011
    Posts
    201
    Thanks
    12
    Thanked 26 Times in 26 Posts
    I dont believe that is the issue.

    if the
    PHP Code:
    !empty($result_array
    which it is not empty, then
    PHP Code:
    array_shift($result_array
    I tested something via

    PHP Code:
     public static function find_by_id($id=0) {
       global 
    $database;   
       
    $result_array self::find_by_sql("SELECT * FROM users WHERE id={$id} LIMIT 1");
       return !empty(
    $result_array) ? array_shift($result_array) : false;
     } 
    PHP Code:
    $user User::find_by_id(1);
    echo 
    $user->full_name(); 
    and it returns the correct info


  •  

    Posting Permissions

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