Function I have (in includes/functions_posting.php):
function url_exists($url) {
$handle = @fopen($url, "r");
if ($handle === false){
return false;
fclose($handle);
}
else{
return true;
fclose($handle);
}
}
Usage (In posting.php):
$your_url = "http://www.somewhere.com/index.php";
$your_url = preg_replace(array('#&\#46;#','#&\#58;#','/\[(.*?)\]/'), array('.',':',''), $your_url);
if (url_exists($your_url))
{
echo 'yeah, its reachable';
}
else
{
echo 'what da hell..';
}
I think it works just fine. I get the text echoed on header with an error saying headers already sent. Instead of echo I now use trigger_error('error message); Now I get the error the way I want it to be,except that no matter what the url I have in $your_url I keep getting the same error that the URL exists even when it's not!
Also,I'd like to make the function work after I click submit topic and not when I click create new topic.
Thanks. :)
Comments
Post a Comment