title: PHP External Link Help
body: <p>Hi I have the following page which sets a cookie with the current URL and also a simple external link.</p>
  
  <pre><code>&lt;?php
  
  function pageURL()
      {
          $pageURL = 'http';
          if ($_SERVER["HTTPS"] == "on")
          {
              $pageURL .= "s";
          }
          $pageURL .= "://";
          if ($_SERVER["SERVER_PORT"] != "80")
          {
              $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
          } 
          else
          {
              $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
          }
          return $pageURL;
      }
  
      $CurrentPage = pageURL();
  
      setcookie('linkback', $CurrentPage);
  
  ?&gt;
  
  &lt;p&gt;&lt;a href="http://www.google.com/"&gt;External Link&lt;/a&gt;&lt;/p&gt;
  </code></pre>
  
  <p>What I want to do is using PHP add a prefix to all external links so that they have have the following structure:</p>
  
  <pre><code>localhost/outgoing?url=http://www.google.com/
  </code></pre>
  
  <p>This loads up an outgoing page like so:</p>
  
  <pre><code>    &lt;?php
  
      if(!isset($_GET['url']))
      {
          header('HTTP/1.0 404 Not Found');
      }
  
      ?&gt;
  
  &lt;h1&gt;Warning! Now leaving website&lt;/h1&gt;
  
      &lt;ul&gt;
                  &lt;li&gt;&lt;a title="Return to Website" href="&lt;?php if(isset($_COOKIE['linkback'])) { echo $_COOKIE['linkback']; } else { echo 'http://localhost:8888/creathive/'; } ?&gt;"&gt;Return to Website&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a title="Continue to &lt;?php echo $_GET['url']; ?&gt;" href="&lt;?php echo $_GET['url']; ?&gt;"&gt;Continue to &lt;?php echo $_GET['url']; ?&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
  </code></pre>
  
  <p>The idea is that using the cookie set in the previous page I can have a simple back button, and also grab the url from the query and allow the user to continue after being warned they are leaving the site.</p>
  
  <p>The problems I have are:</p>
  
  <p>1.) Prefixing external URLS so that they go to the outgoing page</p>
  
  <p>2.) The isset on the top of the outgoing page is supposed to be throwing a 404 if a user visits the outgoing page without a url query string but isn't</p>
  
  <p>3.) Need to make sure that URLS are valid so for example prevent this for happening: <code>localhost/outgoing?url=moo</code></p>