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 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题