警告:未知:您的脚本可能依赖于PHP 4.2.3之前存在的会话副作用

时间:2013-05-22 05:38:29

标签: php register-globals

我在此网站的快捷方式链接中遇到问题:http://smileshort.com/short-anonymous-links-api.html

使用api:http://smileshort.com/api.php?key=534287562&url=google.com

告诉我这个问题

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

function get_vgd($url)
{
$apiurl = "http://smileshort.com/api.php?key=890479270&url=$url";
$ch = curl_init();
$timeout = 3;
curl_setopt($ch,CURLOPT_URL,$apiurl);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo get_vgd("http://www.google.com");

?>

3 个答案:

答案 0 :(得分:2)

会话变量的名称与某个现有的全局变量同名(即$_SESSION['name']$name都存在)。
重命名其中任何一个。

这应该是一个非常重复的问题,因为它刚刚发生在我身上。

答案 1 :(得分:1)

此错误可能还有其他原因。如果其他人来到这个线程,并且知道没有重复的变量。

如果您执行类似

的操作
unset($var);
$_SESSION['sessVar'] = $var;

您将获得相同的警告,因为您将未定义的变量设置为会话变量。未设置通常不存在,仅用于说明目的:)

答案 2 :(得分:0)

我刚遇到这个问题,问题的原因是

未定义页面上调用的变量。

它让我偏离轨道让我非常担心,但现在我已经定义了$ Var它不再打印警告。