Here’s a little something you can add into the Form_validation.php to check urls. One just checks the syntax. The other actually checks to see if the website exists. Feel free to improve the regex as I’m by no means claiming to be an expert! ![]()
// --------------------------------------------------------------------
/**
* Validate URL
*
* @access public
* @param string
* @return string
*/
function valid_url($url)
{
$pattern = "/^((ht|f)tp(s?)\:\/\/|~/|/)?([w]{2}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?/";
if (!preg_match($pattern, $url))
{
return FALSE;
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Real URL
*
* @access public
* @param string
* @return string
*/
function real_url($url)
{
return @fsockopen("$url", 80, $errno, $errstr, 30);
}
Don’t forget to explain to visitors that they don’t need to append “http://” to the url when you’re validating against real_url()!!!
