예제 #1
0
/**
 * Function to login by admin
 */
function login()
{
    if (isset($_REQUEST['username']) & isset($_REQUEST['password'])) {
        include_once '../models/wine.php';
        $obj = new Wine();
        $username = stripslashes($_REQUEST['username']);
        $password = stripslashes($_REQUEST['password']);
        $username = $obj->real_escape_string($username);
        $password = $obj->real_escape_string($password);
        $result = $obj->login($username, $password);
        $row = $result->fetch_assoc();
        if (!$row) {
            echo '{"result":0, "message":"Failed to login"}';
        } else {
            echo '{"result":1, "user_name":"' . $row['user_name'] . '"}';
            session_start();
            $_SESSION['LOGIN'] = "******";
            $_SESSION['username'] = $row['user_name'];
        }
        $result->close();
    }
}