不推荐使用:函数session_is_registered()不推荐使用php中的错误

时间:2015-02-27 15:15:54

标签: php

我试图登录我刚刚编写的网站登录页面,我目前遇到的问题是我已安排的安全协议.I&#39 ; m收到此错误:

  

不推荐使用:函数ereg_replace()在第76行的/home/u143610567/public_html/timecard/lib/security.php中已弃用。不推荐使用:函数ereg()在/ home / u143610567 / public_html / timecard / lib / security中已弃用第78行的.php不推荐:函数ereg_replace()在第76行的/home/u143610567/public_html/timecard/lib/security.php中已弃用不推荐:函数ereg()在/ home / u143610567 / public_html / timecard / lib中已弃用第78行/security.php不推荐使用:函数ereg_replace()在第76行的/home/u143610567/public_html/timecard/lib/security.php中弃用弃用:函数ereg()在/ home / u143610567 / public_html / timecard中已弃用第78行上的/lib/security.php已弃用:函数ereg_replace()在第76行的/home/u143610567/public_html/timecard/lib/security.php中已弃用。不推荐使用:/ home / u143610567 / public_html中不推荐使用函数ereg()第78行/timecard/lib/security.php不推荐使用:函数ereg_replace()在/ home / u143610567 / pub中已弃用第76行的lic_html / timecard / lib / security.php已弃用:第78行/home/u143610567/public_html/timecard/lib/security.php中不推荐使用函数ereg()更改已弃用:函数ereg_replace()在/ home中已弃用第76行/u143610567/public_html/timecard/lib/security.php不推荐使用:函数ereg()在第78行的/home/u143610567/public_html/timecard/lib/security.php中已弃用。不推荐使用:函数session_is_registered()已弃用第32行/home/u143610567/public_html/timecard/templates/topbar/topbar.inc.php不推荐使用:函数ereg_replace()在第76行的/home/u143610567/public_html/timecard/lib/security.php中弃用弃用:功能ereg()在第78行的/home/u143610567/public_html/timecard/lib/security.php中弃用

<?php
class Security {
function authenticate ($user, $pass, $auth_method) {
global $default, $authenticated;

//Start out false
$auth_result = false;
if ($auth_method == 'imap' || $auth_method == 'pop3') {
if ($auth_method == 'pop3') {
$connstr = '{' . $default->server . ':' . $default->port . '/pop3}';
} else { // default to imap connections
$connstr = '{' . $default->server . ':' . $default->port . '}';
}
$auth_result = @imap_open($connstr, $user, $pass);
//Close auth_result since we don't need it anymore
@imap_close($auth_result);
}
elseif ($auth_method == 'db') {
$auth_result = oats_validate_user($user, $pass);
}

if (!$auth_result) {
$this->invalidLogin();
} else {
//Now they're authenticated for the session
$this->start_sess();
$_SESSION[PRIMARY_VAR] = $user;
$_SESSION[AUTHENTICATED_VAR] = true;
$this->successfulLogin();
}
} // authenticate()
function invalidLogin () {
//Never started a session, so we don't have to end one
header("HTTP/1.0 301");
header("Location: " . INVALID_LOGIN_PAGE);
exit;
} // invalidLogin()
function successfulLogin () {
header("HTTP/1.0 301");
$location = $this->addSessToLink(SUCCESS_LOGIN_PAGE); 
header("Location: $location");
exit;
} // successfulLogin()

function start_sess () {
global $default;
session_name($default->sess_name);
session_start();
} // register_sess()
function end_sess () {
//Just in case, set authenticated to false
$GLOBALS['HTTP_SESSION_VARS'][AUTHENTICATED_VAR] = false;
//Have to destroy the cookies since PHP's function is unreliable
$p = session_get_cookie_params();
setcookie(session_name(), "", time() - 3600, $p["path"], $p["domain"]);
session_destroy();
} // end_sess()
function register_variables ($val) {
if (is_array($val)) {
reset($val);
while (list ($k, $v) = each ($val)) {
session_register($v);
} 
} else { //It's just a single variable
session_register($val);
}
} 
function addSessToLink ($link) {
//For HTML encoded variables
$link = ereg_replace("%", "%%", $link);
//If link alread has variables
if (ereg("\?", $link)) {
$newlink = sprintf ($link . '&%s',SID);
} else {
$newlink = sprintf ($link . '?%s',SID);
}
return $newlink;
} // addSessToLink()

function check_auth ($auth) {
//If they're not authenticated, send them to log in page
If (! isset($auth) || ! $auth) {
header("HTTP/1.0 301");
header("Location: " . INVALID_LOGIN_PAGE);
exit;
}
} // check_auth()

} //end class Security
?>

security.php中的第74-84行似乎导致了问题

3 个答案:

答案 0 :(得分:0)

我刚刚意识到我正在使用的php版本,我已经将版本更改为PHP 5.2,看来我已经过时了PHP编码的版本。

答案 1 :(得分:0)

答案 2 :(得分:0)

截至PHP 5.3.0,

session_is_registered()已被弃用,自PHP 5.4.0起已被删除。这意味着升级PHP版本只会让情况变得更糟。你可以改用

if (session_id()) 
{
  //Do whatever you need, as session is registered.
}
else
{
  // Session is not registered. 
}

如果没有会话ID,则不会返回任何内容。有关详细信息,请参阅PHP manual