📜  如何从 cookie 字符串中获取会话变量 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:15.580000             🧑  作者: Mango

代码示例1
connect_error) die ($connect->connect_error);

if (isset($_SERVER['PHP_AUTH_USER']) &&
   isset($_SERVER['PHP_AUTH_PW']))
    {
        $username = mysql_entities_fix($connection,$_SERVER['PHP_AUTH_USER']);
        $password = mysql_entities_fix($connection,$_SERVER['PHP_AUTH_PW']);

        $query = "SELECT * FROM user WHERE username = '$username'";

        $result = $connection->query($query);

        if(!$result) die ($connection->error);
        elseif ($result->num_rows) 
        {
            $row = $result->fetch_array(MYSQLI_NUM);    
            $result->close();
            $salt1="!@#$";
            $salt2="$#@!";
            $token = hash('ripemd128',"$salt1$password$salt2"); 

            if($token == $row[3])
                {
                    session_start();
                    $_SESSION['username'] = $username;
                    $_SESSION['password'] = $password;
                    $_SESSION['forename'] = $row[0];
                    $_SESSION['surname'] = $row[1];
                        echo "$row[0] $row[1] : Hi '$row[0]' you are logged
                            in as '$row[2]'";
                    die("

CLICK HERE TO CONTINUE

"); } else {die("Invalid Username/ Password Combination");} } else { die("Invalid Username/ Password Combination"); } } else { header('WWW-Authenticate: Basic realm="Restricted Section"'); header('HTTP/1.0 401 Unauthorized'); die("Please enter your username and password to Login"); } $connection->close(); function mysql_entities_fix($connection,$var) { return htmlentities(mysql_entities_string($connection,$var)); } function mysql_entities_string($connection,$var) { if (get_magic_quotes_gpc()) $var = stripslahes($var); return $connection->real_escape_string($var); } ?>