내 PHP는 내 PHP Fiddle에서 작동하지만 정확히 2 부에 복사 한 후 .php 문서로 저장하고 내 서버 here on my website에 업로드하지 마십시오. JSON에 존재하는 것으로 생각되는 문제는 정보 권한을 디코딩하지 않고 항상 "잘못된 ID"이지만 피들에서 실행하면 항상 올바른 이름이 3-4 개 이상 제공됩니다. 하지만 크롬, 파이어 폭스, 사파리와 같은 브라우저에서는 절대 이름이 없습니다. 왜 이럴 수 있니?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"를 제공합니다. 그래서 나는 배열이 어떻게 생겼는지 볼 수 print_r($json);
에 else
을 전환하고 이것이 내가 가진 무엇 :
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'을 끄는 제외하고 .. 당신이 얘기하고 있는지? –
@vlzvl 어디에서 사용할 수 있습니까? 피들? 브라우저에서? 나는 아무 경고도 얻지 않는가? 당신의 경고는 무엇입니까? – j0sh1e
내 대답을 확인하십시오. –