所以这就是我想要做的,我登录并在 PHP 中注册,现在我的主要目标是让登录工作,我在这里遇到的困难是当我登录时它不会说,“欢迎'用户名在这里'!” 这是我的代码:
chk.php:
<?php
include 'config.php';
session_start();
$chk = $_SESSION['login_user'];
$sqlses = mysql_query("select username from users where username='$chk'" );
$row = mysql_fetch_array($sqlses);
$user = $_row['username'];
?>
如您所见,我使用 $user 来指代已登录的用户。
这是 myprofile.php:
<?php
include 'chk.php';
?>
<html>
<head>
<link rel="stylesheet" href="main.css" />
<title>RiDDoW Grabber</title>
</head>
<body>
<center>
<?php echo "<h1>Welcome" . $user . "!</h1>" ?>
现在我不确定我做错了什么,但这里也是 login.php:
<?php
include 'config.php';
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
$username = addslashes($_POST['username']);
$password = addslashes($_POST['password']);
$sql = "SELECT id FROM users WHERE username='$username' and password='$password'";
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
$act = $_row['active'];
$count = mysql_num_rows($res);
if($count == 1) {
$_SESSION['login_user'] = $username;
echo "Success! Redirecting.... ";
header("refresh:5;url=myprofile.php");
} else {
echo 'Error 1822: Login or Password is not valid. ';
}
}
?>
没有任何错误或任何它只是说“欢迎!” 我不知道为什么或发生了什么,但我该如何解决这个问题?