我正在使用下面的代码来查看一个网站是否已经关闭。
<?php
if (isset($_POST['submit'])) {
$url = $_POST['url'];
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code == 200) {
echo "<h3>Up!</h3>";
} else {
echo "<h3>Down!</h3>";
}
}
?>
<form action="" method="post">
Url: <input type="text" name="url" /><br />
<input type="submit" name="submit" />
</form>我遇到的问题是,当我检查facebook.com时,它写下来了,但它不是.
为什么要这么做?我原以为可能是https,但谷歌运作得很好。
发布于 2014-02-06 10:27:06
我决定发布更新后的代码,以防其他人有同样的问题。
<?php
if (isset($_POST['submit'])) {
$url = $_POST['url'];
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo "<h3>$code</h3>";
if ($code == 200) {
echo "<h3>Up! with a 200 code</h3>";
}
if ($code == 301) {
echo "<h3>Up! with a 301 code</h3>";
}
else {
echo "<h3>Down!</h3>";
}
}
?>
<form action="" method="post">
Url: <input type="text" name="url" /><br />
<input type="submit" name="submit" />
</form>在上面,您可以看到我添加了以下内容
if ($code == 301) {
echo "<h3>Up! with a 301 code</h3>";
} 有很多离线代码,所以我决定只使用在线代码。
正如Kei在评论中发布的那样,您可以看到返回代码列表这里
我还添加了行echo "<h3>$code</h3>";,这样您就可以从表格ie 200,301中看到响应。
发布于 2014-02-06 10:08:09
https://stackoverflow.com/questions/21599470
复制相似问题