如何替换session_register(“adminuser”);与$ _SESSION?更多信息如下

时间:2013-08-05 17:16:58

标签: php

目前,我的网站是一个Facebook封面网站,使用scripteen facebook封面脚本制作。如果我登录管理面板并且login.php控制登录管理面板,则允许我的管理面板访问:

<?
session_start();
ob_start();
?>
<?php include('../db.php');?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Scripteen FB Covers Script - Admin Control Panel</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<div class="headcontaint">
<div class="logo"><a href="index.html"><img src="../images/logo.png" width="280" height="74"></a></div>

</div>
</header>
<div class="container">
<div class="maintitle">Login to Admin Contol Panel</div>
<?php
$err=isset($_GET['error'])?$_GET['error']:""; 
if($err=='error'){?>
<div class="errormsgbox">Wrong Username or Password. Please try again.</div>    
<?php }

if(!isset($_SESSION['adminuser'])){
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$adminuser=mysql_real_escape_string($_POST['adminuser']); 
$adminpassword=mysql_real_escape_string($_POST['adminpassword']); 
$gpassword=md5($adminpassword); // Encrypted Password
$sql="SELECT id FROM admin WHERE adminuser='$adminuser' and adminpassword='$gpassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

// If result matched $username and $password, table row must be 1 row
if($count==1)
{
session_register("adminuser");

header("location:index.php");
}
else
{
header("location:login.php?error=error");

}
}
ob_end_flush();

?>
<div class="box">
<div class="login_box">
<form action="login.php" method="post">
<div class="login_input">
<label class="loginlbl"  for="adminuser">UserName :</label>
<input type="text" name="adminuser"/>
</div>
<div class="login_input">
<label class="loginlbl"  for="adminpassword">Password :</label>
<input type="password" name="adminpassword"/>
</div>
<div class="login_submit">
<input type="submit" id="submit" value=" Login to Admin Contol Panel"/>
</div>
</form>
</div>

</div>
<?php }else{
header("location:index.php");
}

include('footer.php');
?>

但是,在PHP 5.4.0中不推荐使用session_register和session_is_registered。如何让这段代码工作,以便它能与5.4.0一起使用?

我真的不知道要对它进行哪些修改,请帮我解决这个问题。

2 个答案:

答案 0 :(得分:1)

Php.net声明如下:

// Use of session_register() is deprecated
$barney = "A big purple dinosaur.";
session_register("barney");

// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["zim"] = "An invader from another planet.";

答案 1 :(得分:0)

符合 42 * 更改 *

session_register("adminuser");

$_SESSION['adminuser'] = $adminuser;

由于