直到最后一行我的代码工作正常,
如果第一个链接断开,第2页将会打开,
如果第2页被破坏,则应打开第3页。
<?php
$clientproiptv = file_get_contents('/clientproiptv.txt', true);
$paliptv = file_get_contents('/paliptv.txt', true);
$url1 = 'http://web.com/1';
$url2 = 'http://web.com/2';
$url3 = 'http://web.com/3';
if(get_headers($url1)) {
header('Location:'.$url1);
} else {
header('Location:'.$url2);
}
// ** from here i need help **
else {
header('Location:'.$url3);
}
答案 0 :(得分:2)
试试这个:
if(get_headers($url1))
{
header('Location:'.$url1);
}
else if(get_headers($url2)){
header('Location:'.$url2);
}
else{
header('Location:'.$url3);
}
答案 1 :(得分:2)
您应该像else if
那样使用:
<?php
$clientproiptv = file_get_contents('/clientproiptv.txt', true);
$paliptv = file_get_contents('/paliptv.txt', true);
$url1 = 'http://web.com/1';
$url2 = 'http://web.com/2';
$url3 = 'http://web.com/3';
if(get_headers($url1)){
header('Location:'.$url1);
} else if(get_headers($url2) {
header('Location:'.$url2);
} else {
header('Location:'.$url3);
}
?>
答案 2 :(得分:1)
您正在寻找elseif
(PHP 4,PHP 5,PHP 7):
示例代码:
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
文档: http://php.net/manual/en/control-structures.elseif.php
其他解决方案:
在elseif
旁边,您可以使用switch
(PHP 4,PHP 5,PHP 7):
<?php
switch ($i) {
case "apple":
echo "i is apple";
break;
case "bar":
echo "i is bar";
break;
case "cake":
echo "i is cake";
break;
}
?>