Improve file_get_contents(). Fixes #38.

This commit is contained in:
Tom Slominski
2017-04-15 20:42:25 +01:00
parent 3204af9ad6
commit 172f4d80fe

View File

@@ -18,6 +18,21 @@ function display_error( $message, $action = null ) {
die();
}
function get_remote_file( $url ) {
if( function_exists( 'curl_init' ) ) {
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $curl );
curl_close( $curl );
return $output;
} elseif( ini_get( 'allow_url_fopen' ) ) {
return file_get_contents( $url );
} else {
display_error( yourls__( 'Your server doesn\'t support reCAPTCHA. Ask your host to install cURL or turn on allow_url_fopen.', 'isq_translation' ) );
}
}
if ( empty( $_REQUEST['url'] ) ) {
display_error( yourls__( 'You haven\'t entered a URL to shorten.', 'isq_translation' ) );
};
@@ -42,7 +57,7 @@ if ( $antispam_method == 'user_login' ) {
} else if ( $antispam_method == 'recaptcha' ) {
// Google reCAPTCHA is enabled
$recaptcha_data = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . ISQ::$recaptcha['secret'] . '&response=' . $_REQUEST['g-recaptcha-response']);
$recaptcha_data = get_remote_file('https://www.google.com/recaptcha/api/siteverify?secret=' . ISQ::$recaptcha['secret'] . '&response=' . $_REQUEST['g-recaptcha-response']);
$recaptcha_json = json_decode($recaptcha_data, TRUE);
// What happens when the reCAPTCHA was completed incorrectly