title: How to fix open redirect in php?
body: <p>I don't know much about php and i feel dumb asking this question here.
  How can we fix open redirect issues in php? 
  for example in the below code. </p>
  
  <pre><code>if($_GET["target"]) {
      $target =$_GET["target"];
      header("Location: $target");
  }else {
      echo "No target!";
  }
  </code></pre>
  
  <p>I am trying to redirect everything other than <a href="http://localhost:81/" rel="nofollow noreferrer">http://localhost:81/</a>* to <a href="http://localhost:/81" rel="nofollow noreferrer">http://localhost:/81</a> and if i give input <a href="http://localhost:81/something" rel="nofollow noreferrer">http://localhost:81/something</a> comes it should be redirected as it is and all other should be redirected to <a href="http://localhost:81/" rel="nofollow noreferrer">http://localhost:81/</a> . </p>
  
  <p>i tried changing header("Location: <a href="http://localhost:81/" rel="nofollow noreferrer">http://localhost:81/</a>") but it is redirecting everything to <a href="http://localhost:81/" rel="nofollow noreferrer">http://localhost:81/</a>
  How can i edit or fix this to include no redirect for <a href="http://localhost:81/something" rel="nofollow noreferrer">http://localhost:81/something</a> ? </p>