Hi I have a HTML-Form where user's can enter their website-address. Some of you know the resulting problem for sure: most users enter "www.php.net", some users enter "http://www.php.net" and some others enter "http://www.php.net/". The last version is IMHO the most correct form. ("http://www.php.net" is commonly used, but afaik it's either the webbrowser or the webserver which appends the missing /). So my problem was to rewrite the url's so that entered URL's will be displayed correct, no matter how the user entered it. For this purpose I wrote following function:
function rewriteURL($url, $base=""){ $purl = parse_url($url); if (!isset($purl['scheme']) || (!$purl['scheme'])){ $url = "http://".$url; } $purl = parse_url($url); if ((!isset($purl['path'])) || (!$purl['path'])){ $url .= '/'; } return $url; } My Questions: -Are there URLs which could be entered correct and become wrong when rewritten with that function? (Yes, I have tested the function myself, but there are too many possibilities so it's impossible for me to cover all of them) -What was the best way to check, if the give address really exists? (I thought on a test like this: $exists = true; @fopen($url) or $exists = false; return $exists;) TIA Stefan Rusterholz