php 致命错误:调用未定义的函数 session_register()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15179308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Call to undefined function session_register()
提问by Sam
I'm new to php and was wondering if anyone could help me debug, the following error. Fatal error: Call to undefined function session_register()
我是 php 新手,想知道是否有人可以帮我调试,出现以下错误。致命错误:调用未定义的函数 session_register()
It occurs as I get a user to login.
它发生在我让用户登录时。
PHP
PHP
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$myusername=addslashes($_POST['username']);
$mypassword=addslashes($_POST['password']);
$sql="SELECT id FROM admin WHERE username='$myusername' and passcode='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
session_register("myusername");
$_SESSION['login_user']=$myusername;
header("location: welcome.php");
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>
Error it throws out at line 16 is
它在第 16 行抛出的错误是
$active=$row['active'];
回答by Ibu
If you check the php manual, you will see that it has been deprecated
如果您查看 php 手册,您会看到它已被弃用
How about you use the $_SESSIONvariable?
你怎么用这个$_SESSION变量?
$_SESSION["myusername"] = $username;
回答by MIIB
First you only select idfrom database, so there's no $row['active'].
Change $row['active']to $row[0]['id'].
首先你只select id来自数据库,所以没有$row['active']. 更改$row['active']为$row[0]['id']。
And do not use session_register("myusername");Use $_SESSION['myusername']=="something"
并且不要使用session_register("myusername");使用$_SESSION['myusername']=="something"
You could change your query to select id,username ...and then set $_SESSION['myusername']=$row[0]['username'];
您可以将查询更改为select id,username ...然后设置$_SESSION['myusername']=$row[0]['username'];
Ofcourse this method is not good, but for a beginner it should do it;
这种方法当然不好,但是对于初学者来说应该这样做;

