2013-01-23 37 views
-1

Possible Duplicate:
PHP session side-effect warning with global variables as a source of data在php中的會話register_globals警告

我通過PHP獲得Ajax響應。 我得到這個錯誤:

PHP Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

我該如何解決它?

我的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; 
    } 
?> 
+0

正如通知所說:這是_Warning_,而不是_Error_。它有一個完美的解釋它是什麼。那麼你的問題是什麼? – arkascha

+0

如何解決..? –

回答

0

你可以在你的php.ini設置 「了session.bug_compat_warn = OFF」。這應該關閉該警告。

另一種解決方案是將PHP更新到比4.2.3更高的版本。

0

兩個更多的解決方案:

  • 把你的代碼的功能。

    函數中的變量沒有(除非使用global語句)在全局名稱空間中,因此不顯示此錯誤。

  • 不要使用與(已用)會話索引具有相同名稱的變量。在這種情況下,重命名或者$phone$_SESSION['phone']

也有這個預警this answer其他(干擾)的詳細信息。