PHP-在登录表单中制作cookie


PHP - Making cookie in login form

我正试图让一个人登录系统,直到在浏览器中打开页面。我的代码是:

($GLOBALS["___mysqli_ston"] = mysqli_connect($hostname,  $username,  $password)) or DIE('NOT Connected!');
 ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE $dbname")) or DIE('Database name is not available!');
 $login = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM student WHERE (name = '" .addslashes($_POST['username']) . "') and ( password = '" .($_POST['password']) . "')");
 $row=mysqli_fetch_array($login); 
 $a = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM admin WHERE (username = '" .addslashes($_POST['username']) . "') and (password = '" .sha1($_POST['password']) . "')");
 $r=mysqli_fetch_array($a); 
 if($row){
    $_SESSION['user'] = $row['name'];
    $_SESSION['lname'] = $row['lname'];
$_SESSION['pass'] = $row['pass']
setcookie("cookname", $_SESSION['name'], time()+60*60*24*100, "/");
setcookie("cookpass", $_SESSION['pass'], time()+60*60*24*100, "/");
    header ("location: ../../gui-student.php");
    }
    elseif($r){
 $_SESSION['admin'] = $row['id'];
header ("location: gui-admin.php");
    }
    else {
        header ("location: ../../index.html?err");
        }
 if($row==1)
       {
      session_start();
       $_SESSION['username']=$userName;
     header("location: ../../gui-employee.php");
     exit();
     }

我试过了,但没用。我是cookie的新手,我不知道如何查看guid-student.php页面上的cookie
提前感谢

Rgds
Bhawna

要检查cookie,请使用。。

$_COOKIE['cookie_name'];在您的情况下,它将是$_COOKIE['cookname'];$_COOKIE['cookpass'];

这将给出您在cookie中设置的值,即$_SESSION['name']$_SESSION['pass']