这个cURL代码在PHP中有什么问题?

时间:2015-07-31 05:29:49

标签: php curl

我在这里问了一个问题:Send JSON by cURL always returns "No access"

善良的人通过这段代码回答了我:

<?php

//API URL
$url = 'http://www.example.com/test.php';
$data = "?code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b"

//Initiate cURL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Execute the request
$result = curl_exec($ch);

?>

但是,我无法运行它。它返回一个错误:

  

解析错误:语法错误,第8行的D:\ XAMPP \ htdocs \ test.php中的意外T_VARIABLE

我正在使用 PHP 5.3 来完成自己的工作。

有没有解决方法?

2 个答案:

答案 0 :(得分:1)

$data = "?code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b"之后您错过了;

答案 1 :(得分:0)

你在第5行丢失了分号;

<?php

//API URL
$url = 'http://www.example.com/test.php';
$data = "?code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b"; //here

//Initiate cURL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

//Execute the request
$result = curl_exec($ch);

?>