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


Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3

我在这个网站的快捷链接有一个问题: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");
?>

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

这应该是一个非常重复的问题,因为我刚刚想到了。

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

如果你做像

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

将得到相同的警告,因为您将未定义的变量设置为会话变量。unset通常不存在,它只是为了说明目的:)

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

在页面上调用的变量没有定义。

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