Redirect URL

They have: 105 posts

Joined: Mar 2006

I'm trying to redirect users to a user defined URL, but when the url is clicked it can't find the page because the url in the address bar includes my website url as well as the requested url, why is this?

For example,

http://www.nwic.org.uk/www.google.com

How can I make it so that the url is just google.com?

I have used this in the php code, it gets the url from a form on the previous page.

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

He has: 698 posts

Joined: Jul 2005

I don't know how the user inputs the URL, so it's hard to say exactly how you could work around this, but one option would be to have an input field something like this:

...
<ul>
  <li>
    <label for="url">URL: </label>
    http://
    <input type="text" name="url" value="" />
  </li>
</ul>
...
'

In most cases, the user will realize not to put the 'http://' and then in your redirect, you could have something like the following:

<?php
header
("Location: <a href="http://"" title="http://"">http://"</a> . $_POST['url']);
?>
'

Kurtis

They have: 105 posts

Joined: Mar 2006

It was a syntax error, your code works great. Thanks Wink

They have: 105 posts

Joined: Mar 2006

Using the code example you gave me, how would I make it open in a new window?

He has: 698 posts

Joined: Jul 2005

Well, for that sort of thing, the only way I know how to do it is through JavaScript, and I would simply write a completely different code, something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <title>New Window</title>
  &lt;script type="text/javascript"&gt;
  function newUserWindow(url) {
    url = "http://" + url;
    window.open(url,'userWindow','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
  }
  &lt;/script&gt;
  </head>
  <body>
    <form>
      http://<input type="text" name="url" id="url" />
      <input type="submit" name="go" id="go" value="Go!" onclick="newUserWindow(document.getElementById('url').value)" />
    </form>
  </body>
</html>
'
Let me know if you have any questions about what something means. Wink

If you absolutely want to incorporate the code I gave before, I'm not sure how to go about it.

Kurtis

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.