所以一直在网上找了一段时间,并试图按照例子......
我想做的是让用户登录,然后开始一个我已经测试过的会话,它确实有效,但是我无法从数据库中获取用户名或任何其他数据项。
用户使用用户名和密码登录。然后,他们将被引导到具有此代码的另一个页面...
<?php
session_start();
if(!session_is_registered(user_name));
$con = mysql_connect("****","****","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Finds database
mysql_select_db("****", $con);
$result = mysql_query("SELECT * FROM fyp_users;");
$first_name = $_SESSION['first_name'];
$_SESSION['views']=200;
header('location:../profile.php');
?>
会话视图只是一个测试,它可以在用户登录时查找并显示数字。然后我尝试进行 first_name 会话。
这也是它然后重定向的页面......
<?php
$con = mysql_connect("****","****","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Finds database
mysql_select_db("****", $con);
?>
<?php
session_start( );
//$result = mysql_query("SELECT * FROM fyp_users;");
?>
一些 HTML....
<?php
echo "Pageviews=". $_SESSION['views'];
echo "Welcome=" . $_SESSION['$first_name']
?>
它如何不显示名称,我不知道它是否容易修复,有人可以帮助我吗?
- - - - - - - - - - - - - - - - - - - - - - 更新 - - - ----------------------------------
HTML 表格
<div class="login">
<form id="login" method="post" action="includes/checklogin.php">
<p>Login</p>
<p>Username</p>
<input name="user_name" id="user_name">
<p>Password</p>
<input name="password" id="password" type="password">
</br>
<input type="submit" name="Submit" value="Login">
</form>
</div>
<!--<img src="images/logo.png" alt="The Community">-->
</div>
检查登录.php
<?php
$con = mysql_connect("****","***","***");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Finds database
mysql_select_db("****", $con);
$user_name=$_POST['user_name'];
$password=$_POST['password'];
$user_name = stripslashes($user_name);
$password = stripslashes($password);
$user_name = mysql_real_escape_string($user_name);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM fyp_users WHERE user_name='{$user_name}' and password='{$password}'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1) {
session_register("user_name");
session_register("password");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
登录成功,php
<?php
session_start();
if(!session_is_registered(user_name));
$con = mysql_connect("***","****","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Finds database
mysql_select_db("*****", $con);
$result = mysql_query("SELECT * FROM fyp_users;");
$first_name = $_SESSION['first_name'];
$password = $_SESSION['password'];
$_SESSION['views']=200;
header('location:../profile.php');
?>
配置文件.php
<?php
session_start();
echo "Pageviews=". $_SESSION['views'];
echo "Welcome=" . $_SESSION['first_name']
?>
谢谢詹姆斯