Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 允许重定向到不在htdocs(XAMPP)中的URL_Php_Html_Forms_Redirect_Xampp - Fatal编程技术网

Php 允许重定向到不在htdocs(XAMPP)中的URL

Php 允许重定向到不在htdocs(XAMPP)中的URL,php,html,forms,redirect,xampp,Php,Html,Forms,Redirect,Xampp,真的很难让我的表单允许用户根据他们选择的单选按钮访问URL。当我在我的服务器上完成表单时,它会按照预期重定向到专用URL,但是它说找不到对象,还说“在该服务器上找不到请求的URL”。我真的不明白如何将文件保存到htdocs文件夹中以获得网站的URL。用户可能被重定向到的网站选项如下: 以下是我的代码: PHP: HTML: 婴儿名字流行表 婴儿名字流行表 请选择英格兰和威尔士、苏格兰或北爱尔兰。 英国及英国;威尔士 苏格兰 北爱尔兰 如果有任何帮助,我们将不胜感激。好的,首先,你应

真的很难让我的表单允许用户根据他们选择的单选按钮访问URL。当我在我的服务器上完成表单时,它会按照预期重定向到专用URL,但是它说找不到对象,还说“在该服务器上找不到请求的URL”。我真的不明白如何将文件保存到htdocs文件夹中以获得网站的URL。用户可能被重定向到的网站选项如下:

以下是我的代码:

PHP:


HTML:


婴儿名字流行表
婴儿名字流行表
请选择英格兰和威尔士、苏格兰或北爱尔兰。
英国及英国;威尔士
苏格兰
北爱尔兰

如果有任何帮助,我们将不胜感激。

好的,首先,你应该重构你的代码,使之更清晰、更精确,为此,我为你做了,但下次要努力改进:)

redirectForm.php

<?php

$websites = [
    "S" => "http://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/vital-events/names/babies-first-names",
    "EW" => "http://www.ons.gov.uk/ons/rel/vsob1/baby-names--england-and-wales/index.html",
    "NI" => "http://www.nisra.gov.uk/demography/default.asp28.htm",
    // "ANOTHER_PLACE" => "WEBSITE",
    // "ANOTHER_PLACE" => "WEBSITE",
];

$location = isset($_GET['location']) ? $_GET['location'] : false;

foreach ($websites as $key => $value) {
    if ($key === $location) {
        header("Location: ".$value);
    }
}

您好,谢谢您的回复,但这也不起作用。它成功地将用户重定向到专用URL,但找不到该对象。不确定是什么原因导致问题tbh
<!DOCTYPE html>
<head>
  <title>Baby Name Popularity Tables</title>
</head>
<body>
<h1>Baby Name Popularity Tables</h1>
Please select either England and Wales, Scotland or Northern Ireland.
<form action="" method="get">
<table>
<tr> 
<td><input type="radio" name="location" value="EW"/></td>
<td>England &amp; Wales</td>
</tr>
<tr>
<td><input type="radio" name="location" value="S"/></td>
<td>Scotland</td>
</tr>
<tr>
<td><input type="radio" name="location" value="NI"/></td>
<td>Northern Ireland</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Get Baby Names"/></td>
</tr>
</table>
</form>     
</body>
</html>
<?php

$websites = [
    "S" => "http://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/vital-events/names/babies-first-names",
    "EW" => "http://www.ons.gov.uk/ons/rel/vsob1/baby-names--england-and-wales/index.html",
    "NI" => "http://www.nisra.gov.uk/demography/default.asp28.htm",
    // "ANOTHER_PLACE" => "WEBSITE",
    // "ANOTHER_PLACE" => "WEBSITE",
];

$location = isset($_GET['location']) ? $_GET['location'] : false;

foreach ($websites as $key => $value) {
    if ($key === $location) {
        header("Location: ".$value);
    }
}
<!DOCTYPE html>
<head>
  <title>Baby Name Popularity Tables</title>
</head>
<body>
<h1>Baby Name Popularity Tables</h1>
Please select either England and Wales, Scotland or Northern Ireland.
<form action="redirectForm.php" method="get">
<table>
<tr> 
<td><input type="radio" name="location" value="EW"/></td>
<td>England &amp; Wales</td>
</tr>
<tr>
<td><input type="radio" name="location" value="S"/></td>
<td>Scotland</td>
</tr>
<tr>
<td><input type="radio" name="location" value="NI"/></td>
<td>Northern Ireland</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Get Baby Names"/></td>
</tr>
</table>
</form>     
</body>
</html>