-1

可能重复:
使用全局变量作为数据源的 PHP 会话副作用警告

我通过 PHP 从 Ajax 获得响应。我收到此错误:

PHP 警告: 未知:您的脚本可能依赖于在 PHP 4.2.3 之前存在的会话副作用。请注意,除非启用了 register_globals,否则会话扩展不会将全局变量视为数据源。您可以通过分别在第 0 行的未知中将 session.bug_compat_42 或 session.bug_compat_warn 设置为 off 来禁用此功能和此警告

我该如何解决?

我的 PHP 脚本是

<?php

    include("include/config.inc.php");

    $name = $_POST['loginname'];
    $phone = $_POST['logintelephone'];

    // To protect MySQL injection
    $name = stripslashes($name);
    $phone = stripslashes($phone);
    $name = mysql_real_escape_string($name);
    $phone = mysql_real_escape_string($phone);

    $query  = mysql_query("select * from chatapp_users where name = '$name' and phone_no  = '$phone'");
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($query);
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count > 0){
        $result = mysql_fetch_array($query);
        session_start();
        $_SESSION['currentuser'] = $name;
        $_SESSION['currentuserid'] = $result['user_id'];
        $_SESSION['phone'] = $result['phone'];
        echo 1;
    }else {
        echo 2;
    }
?>
4

2 回答 2

0

还有两个解决方案:

  • 将您的代码放入函数中。

    函数中的变量不在global全局命名空间中(除非您使用语句),因此不会显示此错误。

  • 不要使用与(使用的)会话索引同名的变量。在这种情况下,重命名$phone$_SESSION['phone']

在这个答案中还有关于这个警告的其他(令人不安的)细节。

于 2013-01-23T10:00:43.480 回答
0

您可以在 php.ini 中设置“session.bug_compat_warn = off”。这应该关闭该警告。

另一种解决方案是将 PHP 更新到高于 4.2.3 的版本。

于 2013-01-23T09:03:44.113 回答