PHP 正在执行和显示为文本


PHP executing AND Being displayed as text

我的网站上有php,可以为多个网站创建搜索框。我只是设置了虚拟主机(子域)并将搜索目录移动到其中。完成此操作后,PHP 现在显示在页面上,并且成功执行。我不知道它是如何做到这两点的,但它确实做到了。代码如下:

<html>
<body>
<?php
if (isset($_GET['q'])){
 $query = $_GET['q'];
 echo "<meta http-equiv='"refresh'" content='"0;URL=http://www.google.co.uk/search?q=$query'">";
}
if (isset($_GET['p'])) {
 $yquery = $_GET['p'];
 echo "<meta http-equiv='"refresh'" content='"0;URL=http://uk.search.yahoo.com/search?p=$yquery'">";
}
if (isset($_GET['yt'])) {
 $ytquery = $_GET['yt'];
 echo "<meta http-equiv='"refresh'" content='"0;URL=http://www.youtube.com/results?search_query=$ytquery'">";
}
if (isset($_GET['amz'])) {
 $amzquery = $_GET['amz'];
 echo "<meta http-equiv='"refresh'" content='"0;URL=http://www.amazon.co.uk/s/keywords=$amzquery'">";
}
if (isset($_GET['eby'])) {
 $ebyquery = $_GET['eby'];
 echo "<meta http-equiv='"refresh'" content='"0;URL=http://www.amazon.co.uk/sch/i.html/_nkw=$ebyquery'">";
}
?>

<div id="searchForms">
<form id="gSearch" method="GET" action="http://www.google.co.uk/search"  />
<input type="text" name="q" placeholder="Google UK" value='' />
<input type="submit" value="Google Search"/>
</form>
<form id="ySearch" method="GET" action="http://uk.search.yahoo.com/search" />
<input type="text" name="p" placeholder="Yahoo" value='' />
<input type="submit" value="Yahoo Search"/>
</form>
<form id="ytSearch" method="GET" action="http://www.youtube.com/results" />
<input type="text" name="search_query" placeholder="YouTube" value='' />
<input type="submit" value="YouTube Search"/>
</form>
<form id="ebySearch" method="GET" action="http://www.EBay.co.uk/sch/i.html" />
<input type="text" name="_nkw" placeholder="EBay" value='' />
<input type="submit" value="EBay Search"/>
</form>
<form id="amzSearch" method="GET" action="http://www.amazon.co.uk/s/" />
<input type="text" name="keywords" placeholder="Amazon" value='' />
<input type="submit" value="Amazon Search"/>
</form>

</div>

</body>
</html>
这不是

您搜索的内容,但最好使用

header('Location: http://www.google.co.uk/search?q='.quotemeta($query));

和开关/外壳...

非常重要的是,检查您对安全模式的输入。开放式 Web 应用程序安全项目

PHP 不是 nescassery,实际上对搜索框没有任何作用。<?php?>之间的所有内容都可以而且应该删除,因为表单的 action 属性已经在执行重定向。