【发布时间】:2016-09-03 03:01:50
【问题描述】:
我想为网站创建一个登录会员区。这是我用来登录的表格:
<table width="300" border="0"
align="center" cellpadding="0"
cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="/mainsite/home/login/validate_login.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login
</strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input
name="myusername" type="text"
id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword"
type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit"
value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
所以我有这个表单数据发送到的页面的代码
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username",
"$password")or die("cannot connect");
mysql_select_db("$db_name")or
die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail
about MySQL injection)
$myusername =
stripslashes($myusername);
$mypassword =
stripslashes($mypassword);
$myusername =
mysql_real_escape_string($myusername);
$mypassword =
mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name
WHERE username='$myusername' and
password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and
$mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword
and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
但是,当我尝试登录时,它给了我这个错误:
致命错误:在第 33 行调用 /home/scaledtothee/public_html/mainsite/home/login 中未定义的函数 session_register()
这是什么意思?
【问题讨论】:
-
session_register 自 PHP 5.3.0 起已弃用,自 PHP 5.4.0 起已移除
-
这正是它所说的。您正在使用软件不知道的功能。如果您在 Google 中复制粘贴了该功能,您会发现很多关于此的主题。其中之一就是这个stackoverflow.com/questions/3682615/…。发帖前请先搜索。
-
我确实搜索过...过去两周我一直在搜索...是什么让您认为我没有搜索过?
-
是什么让您认为我没有? 事实上,搜索和找到许多答案非常容易。你用的是什么版本的PHP。