重定向到PHP中的另一个URL

时间:2015-08-10 12:16:31

标签: 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="Redirect" id="form_submit"/>

</form>

</body>

</html>

我希望被重定向到网站,我在输入值中发布。

4 个答案:

答案 0 :(得分:0)

尝试这样的事情?

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

?>

答案 1 :(得分:0)

提交表单后,您将在任何HTML输出之前使用header()检测表单提交和重定向。在打开<html>之前将其放在页面顶部(假设您在php文件中):

<?php
if ((isset($_GET['site'])) && ($_GET['site'] != '')){

    header("Location: ".$_GET['site']);
    exit;
}
?>

答案 2 :(得分:0)

$url = $_POST['url'];
header("Location: $url");
die();

答案 3 :(得分:0)

您可以尝试以下代码

<?php

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