1 回答

TA貢獻1803條經驗 獲得超3個贊
函數(shù)的返回值并不總是對訪問者可見。您應該使用 echo、print 或 print_r。
function index() {
$id = htmlentities($_GET['id']);
$word = "Alert";
echo $word;
return true;
}
你也可以使用 JSON with json_encode 來編碼
function index() {
$id = htmlentities($_GET['id']);
$word = "Alert";
echo json_encode(['word' => $word]);
return true;
}
和 json_decode 解碼:
function pass_to_res($id)
{
$url = "https://example.com/serverMonitor?id=$id";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$result = curl_exec($ch);
curl_close ($ch);
$result = json_decode($result);
return isset($result['word']) ? $result['word'] : false;
}
- 1 回答
- 0 關注
- 168 瀏覽
添加回答
舉報