我制作了这个脚本,即使我更改了config.yml 的内容,它也只执行默认情况
<?php
$myfile = fopen("config.yml", "r") or die("Unable to open file!");
echo fread($myfile,filesize("config.yml"));
$content = fread($myfile,filesize("config.yml"));
switch ($content) {
case "1":
echo '<script script type="text/javascript">';
echo 'window.location.href ="office365/index.html";';
echo '</script>';
case "2":
echo '<script script type="text/javascript">';
echo 'window.location.href ="connection_reset/index.html";';
echo '</script>';
case "3":
echo '<script script type="text/javascript">';
echo 'window.location.href ="minimal/index.html";';
echo '</script>';
default:
echo '<script script type="text/javascript">';
echo 'window.location.href ="noconfigured.html";';
echo '</script>';
}
fclose($myfile);
?>
我的config.yml内容:1
如果你有什么想法,请帮忙。
因为在每种情况下都没有使用break,所以echo值将设置为默认值:
echo '<script script type="text/javascript">';
echo 'window.location.href ="noconfigured.html";';
echo '</script>';
为了解决这个问题,只需在每个案例后添加一个break语句:
case "1":
echo '<script script type="text/javascript">';
echo 'window.location.href ="office365/index.html";';
echo '</script>';
break;
case "2":
echo '<script script type="text/javascript">';
echo 'window.location.href ="connection_reset/index.html";';
echo '</script>';
break;
case "3":
echo '<script script type="text/javascript">';
echo 'window.location.href ="minimal/index.html";';
echo '</script>';
break;
default:
echo '<script script type="text/javascript">';
echo 'window.location.href ="noconfigured.html";';
echo '</script>';
break;
我刚刚忘记了休息,我用file_get_contents()来完成。
这样人们就可以拥有上面代码的工作版本:
<?php
$myfile = fopen("config.yml", "r") or die("Unable to open file!");
echo fread($myfile,filesize("config.yml"));
$content = file_get_contents("config.yml");
switch ($content) {
case "1":
echo '<script script type="text/javascript">';
echo 'window.location.href ="office365/index.html";';
echo '</script>';
break;
case "2":
echo '<script script type="text/javascript">';
echo 'window.location.href ="connection_reset/index.html";';
echo '</script>';
break;
case "3":
echo '<script script type="text/javascript">';
echo 'window.location.href ="minimal/index.html";';
echo '</script>';
break;
default:
echo '<script script type="text/javascript">';
echo 'window.location.href ="noconfigured.html";';
echo '</script>';
break;
}
fclose($myfile);
?>