I am trying to use reCAPTCHA globally by following the instructions present at https://developers.google.com/recaptcha/docs/faq#can-i-use-recaptcha-globally . However, it is not working for me.
I replaced all the occurrences of "https://www.google.com/recaptcha" with "https://www.recaptcha.net/recaptcha" but what I noticed is it is still referring to google.com internally.
https://www.recaptcha.net/recaptcha/api.js is making a call to https://www.gstatic.com/recaptcha/releases/TPiWapjoyMdQOtxLT9_b4n2W/recaptcha__en.js and it is internally referring to google.com host.
Looks like ReCaptcha code is broken to me. Any ideas on this?
As stated by some comments, google's system choose the best URL, you can't force it to get from recaptcha.net. Trying to override your link may break it at anytime as stated in this post from recaptcha's support group
Using recaptcha.net for this problem is NOT going to solve the problem because it will again call back google.com.
So here I have one solution. The solution is using cURL. When you do requests from cURL it does not actually go from the client but it works as a proxy between the user and the server.
In PHP language you can do it in this way:
reCaptcha.php
<?php
if (! function_exists ( 'curl_version' )) {
exit ( "Enable cURL in PHP" );
}
$ch = curl_init ();
$timeout = 0; // 100; // set to zero for no timeout
$myHITurl = "https://www.google.com/recaptcha"; //domain which is blocked
curl_setopt ( $ch, CURLOPT_URL, $myHITurl );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt($ch, CURLOPT_POSTFIELDS,
"text=/");
$file_contents = curl_exec ( $ch );
if (curl_errno ( $ch )) {
echo curl_error ( $ch );
curl_close ( $ch );
exit ();
}
curl_close ( $ch );
// dump output of api if you want during test
echo "$file_contents";
?>
So you can make a request to this reCaptcha.php file and use the output of this reCaptcha.php page as the response.
If you are not using PHP you can do this with your own project's programming language. You may also need some modification according to your need but you just need to use cURL, the process will remain the same.
But this will be very complex to implement. So, I would advise you to go for another captcha service provider like hCaptcha unless google itself fixes the request sending to google.com from recaptcha.net.
Related
Hi am trying to send multiple files in a php Curl operation. I am using PHP7.2 and trying to send 15 images under the same key.
If I am trying to send just 1 file its working just fine.
$post["image"] = new \CurlFile('image_full_path.png', 'image/png', 'file.png');
But when I am trying to put multiple files its not working anymore.
Already tried
$post["image[0]"] = new \CurlFile('image_full_path.png', 'image/png', 'file.png');
And
$post["image_0"] = new \CurlFile('image_full_path.png', 'image/png', 'file.png');
Does not work
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$path = '/var/www/download/download.pdf';
file_put_contents($path, $response);
echo $response;
I believe you just need to create an associative array to send multiple images with the same key.
$post["image"] = [
new \CurlFile('image_full_path1.png', 'image/png', 'file1.png'),
new \CurlFile('image_full_path2.png', 'image/png', 'file2.png'),
];
It seems like the issue is with my destination of the request. The end point of the curl is written on Python Flask and it seems like if we send it like we do in php, flask dont understand it.
So in php
image[0] => 'image1.png'
image[1] => 'image2.png'
Can be valid and we will get both the files under image key in the request,
in python they are coming in different keys like
image[0] and image[1].
If we are tring to look for image in the request it will give an error, but image[0] and image[1] as a string are working fine.
The solution was to send the files as base 64encoded url in an associative array.
P.S. I am not an expert in Python, so my explanation can be wrong. If some one knows python and is aware if this issue please comment here.
Thank you.
I am trying to delete all classes from Google Classroom using the API. I call Classes.List to retrieve the ID number of all classes, then pass this to Classes.Delete. However at this point I get a 'Requested entity was not found.' error message.
I am unsure how this returns in the List command but fails on Delete. Are there any prerequisites of the Delete command that I cannot see on the Google documentation?
Same happens on the 'Try This API' section of the Google website, so fairly confident it isn't a code issue.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://classroom.googleapis.com/v1/courses");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer $token",
"Content-Type: application/json"
));
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response, true);
foreach ($response['courses'] as $Course)
{
$VLEID=$Course['id'];
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL,
"https://classroom.googleapis.com/v1/courses/".$VLEID);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch1, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer $token"
));
$response1 = curl_exec($ch1);
curl_close($ch1);
var_dump($response1);
echo "<br/>";
die();
}
This seems to be bug on Google classroom side. Please see issue logged in GC issue tracker for this around the same time this question was posted here and the issue creator also mentioned it could be regressed issue as same API was returning different number of courses earlier.
https://issuetracker.google.com/issues/134993210
I'm seeing the same problem in my automated test suite. As far as I can tell, some of the courses being returned from Courses.List is returning courses that have already been deleted. I can't do a Course.Get on the id's either, nor do they show in when browsing courses on the Classroom web page. I know it didn't used to do that because this test suite has been around for years, but I hadn't run it recently, so either there has been a regression somewhere on the Google side, or perhaps it just take a while for the delete to fully propagate. I know the distributed nature of some of these services sometimes manifests in (usually) short term inconsistencies.
I want to create a subgroup that is a subgroup, using API v3, and I'm not sure how to set the condition in the request. For some reason I can't get to the Playground today, so I can't play with it.
I'm thinking something like:
function createSegment($apikey, $dc, $list_id, $name) {
$data = array(
"name"=> $name,
**CONDITION**
);
$data = json_encode($data); // API requires JSON objects
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$dc.".api.mailchimp.com/3.0/lists/".$list_id."/segments");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true); // declare request is POST type
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // set POST data
curl_setopt($ch, CURLOPT_USERPWD, "user:".$apikey); // HTML Basic Auth
$output = curl_exec($ch); // execute and capture response
curl_close($ch);
}
This is what the API Support had to say:
With the release of version 3.0 of our API we made some changes to the structure of how we use IDs. In this case there are currently 2 sets of IDs that groups can be referenced by, depending on which version of the API you are using.
In version 2.0, the group ID is an integer and can be retrieved using the /lists/interest-groupings call here:
https://apidocs.mailchimp.com/api/2.0/lists/interest-groupings.php
With version 3.0, the group ID is a hash and is returned by making a GET request to the Lists Interest Collection endpoint here:
http://kb.mailchimp.com/api/resources/lists/interest-categories/interests/lists-interests-collection
When creating a segment however, we currently only accept the group ID returned in version 2.0 of the API, regardless of whether that segment call is being made with 2.0 or 3.0. For this reason, when segmenting by groups, a call would need to be made to the 2.0 endpoint to retrieve those groups IDs. These IDs are static though, so if they are expected to be updated, they would only need to be requested once and can then be stored locally.
It is posible to download a file using CURLOPT_FILE with Curl (Philip Sturgeon) library?
Right now I'm using, it works but I want to do it with Curl library:
set_time_limit(0);
ini_set('display_errors',true);//Just in case we get some errors, let us know....
$fp = fopen ('/Users/tony/labs/store/'. 'a.mp4', 'w+');//This is the file where we save the information
$ch = curl_init($previewUrl);//Here is the file we are downloading
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
I want something like this:
$file = fopen($to, 'w');
$this->curl->create($url);
$this->curl->option('file', $file);
$this->curl->execute();
fclose($file);
I think using a Library that wraps curl which by itself is already extremely simple is just overkill.
If it does not support it the library is only a single.php file, you could easily add that one line of code in there and it would support it.
I got this strange problem for long and have been trying to solve it without any success.
I got a CI site based on CI 1.7.2. It works fine for most of the time. But many a time it does not.
The problem is, we fill up up a form with many fields and submit it to a method in the controller which does the checking. It then posts the data to the third party web service using curl.
I have a error/order response tracker setup, which mails me every time I get response back from the API. The mail content is of the format:
Order ID: 5876 Result length - 8056 or
Order ID: 5877 Result length - 1121 ....and so on for each order.
Now, many a time I get mail like:
Order ID: Result length - 34441 (Please note the order id is missing here)
Order ID: Result length - 9700
Now , the code for my mail happens to be
mail('myemail#xyz.com','Order ID: '.$this->session->userdata('SITE_ORDER_NO').' Result length - '. $lengthResponse , $orderResult, $headers);
So its seems the,
$this->session->userdata('SITE_ORDER_NO')
segment of the code does not have the Order ID any more. As such the API response is not getting saved in the database . Also I got few reports that the user was logged out of the website after it transferred him to the next page , after the response came back.
My session setup is:
$config['sess_cookie_name'] = 'cisessionJHGJHSOMECAPITALLETTERS';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'user_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
The code of the helper function is:
function call_order_curl($postVars){
$posturl = "API_URL";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,300);
curl_setopt($ch,CURLOPT_TIMEOUT,600);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postVars);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
return $response;
}
I would really appreciate any help on this. Thank you.