我想通過php做300重定向,但首先我想要腳本將檢查網站是否在線,如果在線,則它會重定向,否則它將顯示無法重定向。任何人都可以告訴我怎麼可能? 感謝檢查網站後的PHP重定向是
0
A
回答
2
這應該這樣做(編輯出於最優)
$destination = 'http://www.google.com';
$ch = curl_init($destination);
// use request type HEAD because it's faster and lighter
curl_setopt($ch, CURLOPT_NOBODY, true);
// prevent curl from dumping any output
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// prevent curl from producing any output
curl_setopt($ch, CURLOPT_HEADER, false);
// run request
curl_exec($ch);
// consider request a success if the HTTP Code is less than 400 (start of errors)
// change this to whatever you expect to get, e.g. "equal to 200 (OK)"
$success = (bool) ((int)curl_getinfo($ch, CURLINFO_HTTP_CODE) < 400);
curl_close($ch);
// redirect or die
if ($success) {
header('Location: ' . $destination, true, 301);
} else {
die('Unable to redirect to <a href="'.$destination.'">'.$destination.'</a>');
}
+0
謝謝Dereleased這就是我想要做的。 – DAKSH
+0
不客氣,快樂的編碼! – Dereleased
相關問題
- 1. 檢查重定向地址是網站本身 - PHP
- 2. PHP重定向到網站
- 3. 檢查Facebook網址是否重定向?
- 4. PHP:檢查URL是否重定向?
- 5. php重定向檢查
- 6. 重定向PHP網站上的問題
- 7. 重定向在php中的網站
- 8. 多個301重新定向後的網站(SEO)重定向
- 9. Ajax檢查網址是否存在然後重定向
- 10. 網站重定向
- 11. 網站重定向
- 12. java和網站重定向檢測
- 13. 隨機時間後重定向網站
- 14. PHP - 用信息重定向網站
- 15. 301在Windows上重定向php網站
- 16. 從框架內重定向網站PHP
- 17. PHP curl重定向到其他網站
- 18. 以下重定向和檢查網站的IP - Ruby
- 19. 選擇後檢測並重定向到移動網站
- 20. 網站重定向到移動網站
- 21. 以編程方式檢查網站重定向
- 22. Curl:(51)嘗試檢查我的網站是否正確重定向時出錯
- 23. 移動 - 在移動重定向後查看完整網站
- 24. PHP檢測URL是否重定向並重試重定向
- 25. 檢測是網站在iframe中打開並重定向
- 26. 重定向之前檢查網址symfony2
- 27. 重定向網站用戶
- 28. 重定向從ASP.NET網站
- 29. htaccess重定向網站
- 30. 網站頁面重定向
定義 「在線」。在HTTP請求中將'200 OK'返回到'/'? – Matchu