Redirect URL
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']);
kazimmerman posted this at 22:41 — 26th August 2007.
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
drew22299 posted this at 22:53 — 26th August 2007.
They have: 105 posts
Joined: Mar 2006
It was a syntax error, your code works great. Thanks
drew22299 posted this at 22:54 — 26th August 2007.
They have: 105 posts
Joined: Mar 2006
Using the code example you gave me, how would I make it open in a new window?
kazimmerman posted this at 23:33 — 26th August 2007.
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>
<script type="text/javascript">
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');
}
</script>
</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.
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.