I have a PHP script that redirects the user to a website that they input into the text box. If the user types http://www.google.com into the box Google.com would be loaded and if they type http://facebook.com (without the www) Facebook.com would be loaded. Is there any way I can make it so that the script will only go to the address if it has www. in front of it? I hope you can understand my question.
My PHP script is:
<?php
if($_GET){
header('Location:http://'.$_GET['q']);
}
?>
<form method='get' action=''>
<input type='text' name='q'>
<input type='submit'>
</form>
As Jonhoo noted it’s probably better to use:
This makes sure it also works when there are some (or all) uppercase characters in the www-part of the string.