PHP会话出错
I wrote a script to allow people to log in to an admin side of the site to update events. It worked for about 2 months no problems. I got a call about two days ago that users are getting error when trying to log in. The error they are getting is "Fatal error: Call to undefined function session_register() in /home/smslive/public_html/app/themes/church2/church2/admin/checklogin.php on line 29". If anyone has any ideas on how to fix it I would greatly appreciate it.
Here is the code for "checklogin.php":
<?php
ob_start();
$host="localhost";
$username="username";
$password="password";
$db_name="database";
$tbl_name="table";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['email'];
$mypassword=$_POST['password'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE email='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
session_register("email");
session_register("password");
header("location:/admin/edit.php");
}
else {
echo header("location:/admin/fail.php");
}
ob_end_flush();
?>
Here here is the session for the edit.php
session_start();
if(!session_is_registered("email")){
header("location:/admin/index.php");
}
?>
我写了一个脚本,允许人们登录网站的管理员端来更新事件。 它工作了大约2个月没有问题。 我在两天前接到一个电话,说用户在尝试登录时遇到错误。他们得到的错误是“致命错误:在/ home / smslive / public_html / app / themes中调用未定义的函数session_register() 第29行/church2/church2/admin/checklogin.php“ strong>。 如果有人对如何解决它有任何想法我会非常感激。
此处为 edit.php strong> p>
的会话 在session_start(); \ NIF(session_is_registered( “电子邮件”)!){
header( “位置:/admin/index.php”); \ N}
&GT;
代码 > pre>
div>
这是“checklogin.php”的代码 strong>: p>
&LT; PHP
ob_start();
$的主机= “本地主机”;
$的用户名= “用户名”;
$的密码= “密码”;
$的DB_NAME = “数据库” ; \ N $ tbl_name = “表”;
mysql_connect(“$ host”,“$ username”,“$ password”)或死亡(“无法连接”);
mysql_select_db(“$ db_name”)或死亡(“无法选择数据库”);
\ n $ myusername = $ _ POST ['email'];
$ mypassword = $ _ POST ['password'];
$ myusername = stripslashes($ myusername);
$ mypassword = stripslashes($ mypassword); \ n $ myusername = mysql_real_escape_string($ myusername);
$ mypassword = mysql_real_escape_string($ mypassword);
$ sql =“SELECT * FROM $ tbl_name WHERE email ='$ myusername'和password ='$ mypassword'”;
$的结果= mysql_query($ SQL);
$的计数= mysql_num_rows($结果);
如果($计数== 1){
session_register( “电子邮件”);
session_register (“password”);
header(“location:/admin/edit.php”);
}
else {
echo header(“location:/admin/fail.php”);
}
ob_end_flush ();
?&gt;
code> pre>
session_register
no longer exists. To set session variables, make sure you call session_start
at the start of your script, then simply do:
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
To check if a session variable is set, just do:
if(!isset($_SESSION["email"])){
header("location:/admin/index.php");
}
session_register
has been deprecated as seen on php.net
Just use the $_SESSION
array directly, e.g. $_SESSION['email'] = '';
and if(!isset($_SESSION['email']))
Has your PHP version been updated by the host, Session_register() is deprecated as of php 5.3
Check a phpinfo to find out,
I believe your server has experienced an upgrade in the last two months to >5.4 without your knowledge. session_register()
is no longer available in PHP 5.4