dongyinglan8707 2013-10-11 15:52
浏览 15
已采纳

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");
}
?>
  • 写回答

4条回答 默认 最新

  • doudansui6650 2013-10-11 15:56
    关注

    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");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址