【发布时间】:2014-12-23 00:04:12
【问题描述】:
我正在尝试使用此 javascript 函数进行重定向,该函数可以向用户显示重定向消息并重定向到给定的 URL,但每当我尝试运行 php 时都会出现错误
<?php
include 'theme.php';
/*ceklogin();*/
css();
if($_POST['wget-send'])
{
$dir=$_POST['dir'];
$link=$_POST['link'];
/*exec('cd '.$dir,$out);*/
exec('echo '.$link.' > /tmp/wget-download-link.txt',$out);
exec('wget -P '.$dir.' -b -i /tmp/wget-download-link.txt -o /www/wget.log -c -t 100 -w 10',$out);
echo $out[2];
echo "
<script type="text/javascript">
function Redirect()
{
window.location="http://www.google.com";
}
document.write("You will be redirected to a new page in 5 seconds");
setTimeout('Redirect()', 5000);
</script>
";
exit();
}
echo "<br><br><form action=wget_log.php method=\"post\">";
echo "Download directory :<br><input type=\"text\" name=\"dir\" size=\"15\" value=\"/mnt/usb/\"/><br>";
echo '<br>Download link :<br>';
echo "<textarea name=\"link\" rows=\"4\" cols=\"35\"></textarea><br><br>";
echo '<input type="submit" name="wget-send" value="Send" />';
echo "</form></div>";
foot();
echo '
</div>
</body>
</div>
</html>';
?>
错误提示:
Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';' in /www/wget.php on line 14
我哪里做错了?
【问题讨论】:
-
语法高亮显示明显错误
-
为什么你甚至需要在 php 中使用
echo编写 javascript?如果您甚至无法看到已经突出显示的简单语法错误,建议您不要尝试混合两种语言 -
这不是制作模板的理想方式。考虑以 HTML 模式(即在 PHP 标记之外)编写所有 HTML 和 JavaScript,并且仅在需要时才进入 PHP。见an example here。
标签: javascript php