-1

错误是这样的:

致命错误:在第 3 行的 C:\xampp\htdocs\sigh\login_success.php 中调用未定义函数 session_is_registered()

这是编码:

main_login.php

<html>
<head>
<title>User Registration Form</title>

</head>

<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.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>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

检查登录.php

<?php
session_start();
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="1234"; // 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["myusername"]=$myusername;
$_SESSION["mypassword"]=$mypassword;
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

注销.php

<?php 
session_start();
session_destroy();
?>

登录成功.php

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

<html>
<body>
Login Successful
</body>
</html>

这里似乎有什么问题?

4

3 回答 3

2

session_is_registeredC:\xampp\htdocs\sigh\login_success.php开始删除line 3

这个函数在 PHP5.4 中被移除。文档

如果出于某种原因需要它,请考虑将 php 降级为 php <= 5.3

于 2013-10-30T13:29:44.813 回答
0

session_is_registered 自 PHP 5.3.0 起已弃用,自 PHP 5.4.0 起已移除

于 2013-10-30T13:30:23.743 回答
0

手册说,

自 PHP 5.3.0 起,该函数已被弃用,自 PHP 5.4.0 起已移除。

检查 $_SESSION 是否处于活动状态

if(isset($_SESSION['login']) && !empty($_SESSION['login']) ){
  //do something
}
于 2013-10-30T13:35:04.603 回答