简体   繁体   中英

cURL not working on Google Compute engine

I'm facing a similar issue to this question on my VM instance that runs WordPress:

PHP - Retrieve Facebook image in Google Compute Engine

I'm using AJAX to call send_otp.php with mobile_number as a parameter.

My send_otp.php script is:

$mobile_number = $_POST['mobile_number'];
//  Don't do in production, possible RCE
$url = "http://gateway.com/api?numbers=" . $mobile_number. "";
//      Initiate curl
$ch = curl_init();
// Disable SSL verification (Don't do in production)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL, $url);
// Execute
$result = curl_exec($ch);
// Closing
curl_close($ch);
    
$result = json_decode($result, true);

And my Javascript code is as follows:

cust_mob = jQuery('#number');
jQuery.ajax({
    url: 'send_otp.php',
    type: 'POST',
    dataType: 'json',
    data: {
        mobile_nuber: '' + cust_mob.val().toString() + '',
        security: '<?php echo wp_create_nonce('mobile-validate-nonce'); ?>'
    },
    success: function (response) {
        console.log('success');
    }, error: function (response) {
        console.log('success');
    }
});

I've removed a lot of code just to post it here and everything works fine on my local machine WordPress installation using WAMP.

This code is a part of my theme and all I'm doing is zipping the theme folder and uploading it to WordPress after making changes. Everything works fine except this 'curl' part eg login using ajax and updating profile using AJAX is working fine.

Please tell me how to resolve it, or are there any other methods to achieve the same?

Try this lib: https://github.com/azayarni/purl

I use it in my pet-project that hosted on GAE platform and it works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM