-6

I want to Redirect to a website xxx.com from yyy.com

I have this HTML code

<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>

I want to be redirected to the site, I post in the input value.

Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
Newbie
  • 3
  • 1
  • 3
    So what's your question? And before you say, "how do I do it?", remember that questions like that are too broad and will be closed as such. So if you've written any code thus far I highly recommend adding it to your question. You should read "[how do I ask a good question?](http://stackoverflow.com/help/how-to-ask)". – John Conde Aug 10 '15 at 12:19
  • possible duplicate of [POST in PHP AND redirect the user to that page?](http://stackoverflow.com/questions/5546121/post-in-php-and-redirect-the-user-to-that-page) – Kristiyan Aug 10 '15 at 12:19

4 Answers4

0

Try something like this?

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

?>
Kevin P.
  • 401
  • 4
  • 13
0

Once you have submitted your form, you will neded to detect the form submission and redirect using header() before any HTML output. Place this at the top of your page (presuming that you are in a php file) before your opening <html>:

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

    header("Location: ".$_GET['site']);
    exit;
}
?>
MaggsWeb
  • 3,018
  • 1
  • 13
  • 23
  • the if statement don't need extra ``()`` so it could be ``if (isset($_GET['site']) && !empty($_GET['site'])){`` with the ``empty`` method it look more fabulous. – jmattheis Aug 10 '15 at 12:27
0
$url = $_POST['url'];
header("Location: $url");
die();
Inceddy
  • 760
  • 1
  • 6
  • 18
0

You can try this below code

<?php

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