This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Website Ping
#1

I recently noticed that the Commentics demo was failing to check whether entered websites existed. Some people have been entering made up websites in the website field and the script was allowing this. Upon further inspection, I found that the check was working correctly on localhost but not online. I have come up with a different solution which is working both on localhost and online.

Replace the validate_website() function in comments/includes/functions/processor.php with this:
PHP Code:
<?php 
function validate_website ($website) { //checks whether website was valid

global $validate_website_ping; //globalise variables

$website_valid = true; //initialise flag as true

if (!preg_match('/http:\/\/([a-z0-9]{2,}\-?\.[a-z]{2,3})(\.?[a-z]{2,3})?/i', $website)) { //if the submitted website address does not validate
$website_valid = false; //set flag as false
}

if (
$validate_website_ping) { //if website should be pinged

$headers = @get_headers($website);

$check = is_array($headers) ? preg_match('/^HTTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/',$headers[0]) : false;

if (!
$check) {
$website_valid = false; //set flag as false
}

}
//end of if-website-should-be-pinged

if (!$website_valid) { //if invalid website was entered
error(ERROR_MESSAGE_INVALID_WEBSITE); //reject user for invalid website address
}

}
//end of validate-website function

This fix will be included in Commentics v1.2.

Have you completed the interview?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)