We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44231
    • 126 Posts
    hi there this is a simple username and password login module but I cant get it working with sessions
    every time I log in, I always input my username and password twice the same in logging in

    what would be the problem??

    thanks

    if(isset($_SESSION['authuser'])){
        
        echo 'Hello'.'&nbsp'.$_SESSION['authuser'].'&nbsp'.'<a href="[[~[[*id]]]]&logout">'.'LOG OUT'.'</a>';
        
    }else{
        echo $modx->getChunk('form_calendar_login');
    }
    
    $chck_user = "";
    $chck_pwd = "";
    
    if(isset($_POST['logaccnt'])){
    $uname = $_POST['useradmin'];
    $pass = $_POST['pwdadmin'];
    
    $select_user = $modx->query("Select username, password FROM mod_tblaccount WHERE username = '$uname' AND password = '$pass'");
    foreach($select_user as $user){
    $chck_user = $user['username'];
    $chck_pwd = $user['password'];
    }
    if($chck_user == $uname && $chck_pwd == $pass){
    $_SESSION['authuser'] = $chck_user;
    }else{
    echo '<center>Please try Again</center>';
    }
    }
    
    if(isset($_GET['logout'])){
        $_SESSION['authuser'] = null;
    }
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Is there some reason why you don't want to use the existing MODx user management system and the Login package?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 44231
        • 126 Posts
        thanks for the reply

        I choose this method because the username and password come from custom tables and also I dont have an idea if it is possible to use custom tables in log in package.