I have a phpBB forum on my localhost for learning purposes..now I’m trying to do this using PHP :
When a link gets posted,a script checks if the exact link exists and if it does then the process of posting the message doesn’t continue.
EDIT: This is what I have in includes/message_parser.php
function url_exists($url) {
$handle = @fopen($url, "r");
if ($handle === false){
return false;
fclose($handle);}
else{
return true;
fclose($handle);}}
And this is what I have 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..';
}
It works. I can see it echoing what da hell when I post a link that exists,but the problem is that the post gets posted. what I want now is,if the link exists,then don’t allow the post to be posted.
2ND EDIT:
if($submit){
$URL = "http://www.fileserve.com/file/rP59FZ2";
preg_replace(array('#&\#46;#','#&\#58;#','/\[(.*?)\]/'), array('.',':',''), $url);
if(url_exists($url)) {
echo "Link exists!";
}
That’s what I did to prevent submitting the topic when the url exists. not working :\
Checking if link return status code 200 (dunno about 30x)
Using cURL:
Without cURL:
You can play around with it 🙂
UPDATE
To the updated question.
I don’t know exactly how phpBB works or where you’re trying to catch it, but some suggestions to stop the posting might be to check for the link using javascript/jQuery and then disable the submit button alerting/printing a statement as to why the post wasn’t posted.
I’m not that into regex and such, but you would check the post if it contains any link you where looking for, and then “block” the submit of the form.
Something along the lines of:
as extra security, you could disable the submit by default, and only enable it once the javascript has loaded.