I have a search engine using PHP/MySQL. I use this code to display the results from MySQL:
echo "<table width='300px'>
<h4><a href='$url'><b>$title</b></a><br />
$desc<br>
<font color='red'>$url</font></table></h4>
";
}
?>
However, if I add a URL (for example www.google.com) and I click on the title, it links me to http://mysite.com/www.google.com, instead of http://www.google.com.
How can I solve this?
Your
$urlis “www.google.com”, which is not a complete URL.Consequently, your HTML looks like this (you should have posted the resulting HTML, really, as PHP has nothing to do with this):
www.google.comis not a full URL, and so your browser is treating it as a relative path, and thus prepending the current domain.Your
$urlshould be a full URL, like"http://www.google.com".