Warning: Trying to access array offset on value of type null in index.php on line 21

3周前#PHP

下面是我的 PHP 代码,我面临的问题是

Warning: Trying to access array offset on the value of type null in index.php on line 21

Code:

$curl = curl_init();

$url="http://bluesky.panel.tm/stalker_portal/server/load.php?type=itv&action=create_link&cmd=ffrt%20http%3A%2F%2Flocalhost%2Fch%2F4588&JsHttpRequest=1-xml";

curl_setopt_array($curl, array(

CURLOPT_URL => $url,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_HTTPHEADER => array(

"Accept: */*",

"Accept-Encoding: gzip, deflate, br",

"Accept-Language: en-US,en;q=0.9",

"Cookie: mac=00:1A:79:72:E1:B5; stb_lang=en; timezone=GMT",

" Host: bluesky.panel.tm", 

"User-Agent: Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",

"Authorization: Bearer D0CF5357F55F39F7D3A1B907D13C7B16",

),

));

$response = curl_exec($curl);

curl_close($curl);

$zx = json_decode($response, true);

$xxc= $zx["js"]["cmd"];

$regex = '/\b(http?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i';

preg_match_all($regex, $xxc, $matches);

$urls = $matches[0];

// go over all links

foreach($urls as $url) 

{

   header("Location: $url");

} 

?>

在它工作之前,但突然我不知道发生了什么,现在没有反应并且出现问题。

谁能帮我解决这个问题?

回答
A
Alysha Shanahan
3周前

您将“Accept-Encoding: gzip, deflate, br”传递到标头中,这意味着服务器正在发送编码响应。 $response 不是 json,所以 json_decode 返回 null。 将 CURLOPT_ENCODING => 'gzip' 添加到您的 curl_setopt_array,curl 将能够将响应解码为正确的 json 字符串。