-4

Read the full question before saying duplicate post. I didnot see the duplicate of this post. Just try to run this code you will know what I mean. I don't want to redirect because the page has error or page not found etc.

I have a form on one website. After user gives the input I would like to redirect him to the link that he wrote from another website on that field after clicking submit.

$website = "www.google.com/";(This is already given inside the php or html file). But this file is in another server and not on google server.

Now the user gives input "wallet" in the input filed and he clicks submit. the new link opens and the new link is www.google.com/wallet.

    <!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>

<?php
// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {




   if (empty($_POST["website"])) {
     $website = "";
   } else {
     $website = test_input($_POST["website"]);
     // check if URL address syntax is valid (this regular expression also allows dashes in the URL)
     if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
       $websiteErr = "Invalid URL";
     }
   }

}

function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
?>

<h2>Enter a link</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

   Website: <input type="text" name="website">
   <span class="error"><?php echo $websiteErr;?></span>
   <br><br>


   <input type="submit" name="submit" value="Submit">
</form>

<?php
echo "<a target = \"_blank\" href=\"http://www.google.com/$website\">Submit</a>";
?>

This is the rough coding. I want to open the new link after clicking submit but the problem is after clicking submit the variabe is stored in $website and again the user has to click on "Click here to redirect."(on the last line) to go to new link.

Lifestohack
  • 377
  • 4
  • 19

1 Answers1

-2

Try:

header("Location: http://www.google.com/");
exit;
Oleg Dubas
  • 2,320
  • 1
  • 10
  • 24