我的PHP在我的PHP Fiddle中工作,但不是当我将它完全复制到Sublime 2中时,将它保存为.php文件,将其上传到我的服务器here on my website。我认为JSON存在的问题是它没有正确解码信息,并且始终是“无效的ID”,但是如果您在小提琴中运行,它总是会提供至少3-4个正确的名称。但是在Chrome,Firefox或Safari等任何浏览器中,我从来没有得到任何名字。为什么会这样呢?PHP在PHP中使用小提琴但不在浏览器中
<?php
function gen_pix($min, $max, $quantity) {
$numbers = range($min, $max);
shuffle($numbers);
$x_arr = array_slice($numbers, 0, $quantity);
foreach ($x_arr as $key => $value) {
$username = "https://graph.facebook.com/" . $value . "/";
$json = json_decode(file_get_contents($username), true);
if (!isset($json['name'])) {
echo "Invalid ID<br />";
}
else {
echo $json["name"]. '<br />';
}
}
}
$x = 337800042;
$y = 337800382;
$z = 50;
gen_pix($x,$y,$z);
?>
更新:打开了错误报告。
Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /hermes/bosoraweb186/b1303/ipg.joshiefishbeincom/fi/namebook4.php on line 11 Warning: file_get_contents(https://graph.facebook.com/337800127/): failed to open stream: no suitable wrapper could be found in /hermes/bosoraweb186/b1303/ipg.joshiefishbeincom/fi/namebook4.php on line 11
更新2:现在使用的卷曲
这是我的新代码:
<?php
ini_set("display_errors",1);
error_reporting(E_ALL);
function gen_pix($min, $max, $quantity) {
$numbers = range($min, $max);
shuffle($numbers);
$x_arr = array_slice($numbers, 0, $quantity);
foreach ($x_arr as $key => $value) {
$username = "https://graph.facebook.com/" . $value . "/";
if (!function_exists("curl_init")){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $username);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // 60 seconds timeout
$json = curl_exec($ch);
curl_close($ch);
if (!isset($json['name'])) {
print("error");
}
else {
print($json["name"]). '<br />';
}
}
}
$x = 337800042;
$y = 337800382;
$z = 10;
gen_pix($x,$y,$z);
?>
现在,让我对每一行只是 “H”。所以我换了else
到print_r($json);
看到阵列是什么样子,这是我得到了什么:
HTTP/1.1 200 OK Access-Control-Allow-Origin: * Cache-Control: private, no-cache, no-store, must-revalidate Content-Type: application/json; charset=UTF-8 ETag: "f07656bdb736f1a09e1aa2bb16ecce2b3b1f483e" Expires: Sat, 01 Jan 2000 00:00:00 GMT Pragma: no-cache X-FB-Rev: 1135358 X-FB-Debug: Ha05GqDUPxzl4bA3x9xreOZCveNsf8QiOGExgPU9p6c= Date: Tue, 25 Feb 2014 05:12:49 GMT Connection: keep-alive Content-Length: 148 {"id":"337800051","name":"Irem Muftuoglu","first_name":"Irem","last_name":"Muftuoglu","gender":"female","locale":"nb_NO","username":"iremmuftuoglu"}
作品对我来说,除了它得到了很多'warnings'的..是你在说什么? – 2014-02-25 04:12:25
@vlzvl它在哪里适合你?在小提琴?在浏览器中?我没有收到警告?你有什么警告? – j0sh1e
查看我的回答 – 2014-02-25 04:27:40