Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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中的另一个URL_Php_Html_Redirect - Fatal编程技术网

重定向到PHP中的另一个URL

重定向到PHP中的另一个URL,php,html,redirect,Php,Html,Redirect,我想从yyy.com重定向到网站xxx.com 我有这个HTML代码 <html> <head> <title>Redirect Page</title> </head> <body> <form action="" method="get"> <input type="text" name="site" value=""> <input type="submit" value="

我想从yyy.com重定向到网站xxx.com

我有这个HTML代码

<html>

<head>

<title>Redirect Page</title>

</head>

<body>

<form action="" method="get">

<input type="text" name="site" value="">

<input type="submit" value="Redirect" id="form_submit"/>

</form>

</body>

</html>

我想被重定向到该站点,我在输入值中发布。

尝试类似的方法吗

<?php
// Make sure this is the first thing on the page you're posting on.
if isset($_GET['site'])
header('Location: '.$_GET['site']);

?>

提交表单后,您需要在任何HTML输出之前检测表单提交并使用标题重定向。在打开之前,假设您在一个php文件中,请将其放在页面顶部:


您可以尝试下面的代码

<?php

if (!filter_var($_REQUEST['site'], FILTER_VALIDATE_URL) === false) {
  header('Location: ' . $_REQUEST['site'], TRUE, 302);
}

那么你的问题是什么?在你说“我该怎么做?”之前,请记住,像这样的问题太宽泛了,因此将被关闭。因此,如果您已经编写了任何代码,我强烈建议将其添加到您的问题中。您应该阅读。if语句的可能重复项不需要额外的内容,因此它可能是if-isset$\u GET['site']&&!empty$_GET['site']{使用empty方法看起来更棒。
$url = $_POST['url'];
header("Location: $url");
die();
<?php

if (!filter_var($_REQUEST['site'], FILTER_VALIDATE_URL) === false) {
  header('Location: ' . $_REQUEST['site'], TRUE, 302);
}