I have a form which requires a google reCAPTCH to be ticked. It is working perfectly on Local but does not work when I put it on the development server. I have replaced the registered keys to the ones appointed to me by Google.
It keeps outputting the error message.
The method in my form is post.
I do not understand why it doesn't work. Can someone please help me?
Here is my code:
$secretKey = "#######";
$captcha = $_POST['g-recaptcha-response'];
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
$throwErrorMessage = "You are a robot! ";
$throwError = 1;
$isvalid = False;
};
What version of ReCAPTCHA are you using? The docs on Google website here are pretty different than your code. In particular, you use the function file_get_contents while the documentation uses recaptcha_check_answer like in this example:
<?php
require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again."."(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>
Can you post the error message?
Related
Has anyone edited formtoemailpro to use Recaptcha v2? This is the formtoemailpro developer version which gives you a PHP script: (https://formtoemail.com/developer_pricing.php)
I tried changing
// Check reCAPTCHA
if($reCAPTCHA)
{
require_once('recaptchalib.php');
$resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_REQUEST["recaptcha_challenge_field"],$_REQUEST["recaptcha_response_field"]);
if(!$resp->is_valid)
{
$errors[] = "The reCAPTCHA wasn't entered correctly. Go back and try it again (reCAPTCHA said: " . $resp->error . ")";
}
unset($_REQUEST["recaptcha_challenge_field"]);
unset($_REQUEST["recaptcha_response_field"]);
}
to
// Check reCAPTCHA
if($reCAPTCHA)
{
//require_once('recaptchalib.php');
//$resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_REQUEST["recaptcha_challenge_field"],$_REQUEST["recaptcha_response_field"]);
$resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_REQUEST["g-recaptcha-response"]);
if(!$resp->is_valid)
{
$errors[] = "The reCAPTCHA wasn't entered correctly. Go back and try it again (reCAPTCHA said: " . $resp->error . ")";
}
unset($_REQUEST["g-recaptcha-response"]);
}
But got errors.
This page isn’t working
webeg.uk is currently unable to handle this request.
Test is at http://webeg.uk/aaq/
Can anyone point me to the right direction?
I think I have a solution, please feel free to test and critique:
In place of the existing reCaptcha lines in formtoemailpro as above, enter the following:
// Check reCAPTCHA
if($reCAPTCHA)
{
if(isset($_REQUEST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$privatekey&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==true)
{
unset($_REQUEST['g-recaptcha-response']);
}
}
Thank you
I am using twitter login for magento i configure everything but when get the user informations the give the following error.Your credentials do not allow access to this resource [code] => 220. if some body face this type of problem then help me and thanks in advance.
my code is
$CONSUMER_KEY='xxxxxxxxxxxxxxxxx';
$CONSUMER_SECRET='xxxxxxxxxxxxxxxxxxxxxx';
$OAUTH_CALLBACK='http://demo004.fmeaddons.com';
session_start();
$twitteroauth = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET);
$request_token = $twitteroauth->getRequestToken($OAUTH_CALLBACK);
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
if($twitteroauth->http_code==200){
$url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
echo $url;
$twitteroauth = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']); $_SESSION['access_token'] = $access_token;
$user_info = $twitteroauth->get('account/verify_credentials');
print_r($user_info);
} else {
die('Something wrong happened.');
}
Make sure your keys were created with the correct permissions. You can check this in the "Keys and tokens" section of your Twitter developer dashboard:
I know that this question has been asked many times however in my case the suggested codes and solutions aren't cutting it. The network reply is still my case empty and the error code is 0.
Here's my function:
QString NWork::send(QVector<QString> &data) const{
//QNetworkAccessManager qnam = new QNetworkAccessManager();
QNetworkAccessManager qnam;
try{
QString json = NWork::to_JSON(data);
QByteArray json_data(json.toUtf8());
QNetworkRequest request;
request.setUrl(QUrl(NWork::connection));
request.setRawHeader("Content-Type", "application/json");
request.setRawHeader("Content-Length", json_data);
reply = qnam.post(request, json_data);
//reply = qnam.get(request);
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QString s(reply -> readAll());
qDebug()<<"code "<<status<<"Content "<<s;
//return QString::fromUtf8(response.data(),response.size());
}catch(std::exception x){
std::cout<<x.what()<<std::endl;
}
return "";
}
Making connections of the form suggested by many like
connect(qnam,SIGNAL(destroyed(QNetworkReply*)),this,SLOT(read(QNetworkReply*)));
have no effect on all. The request is reaching the PHP script and I know this by writing the request data in a file. It does so for every request. Echoing anything back even with a text/html header is not working.
Yes, I have tried my PHP script with a HTML AJAX request program and it works. It writes to file, and returns a response to the browser. Same code in both cases.
Here's my PHP code:
header("Access-Control-Allow-Origin: *");
$k = file_get_contents("php://input");
$file = "/file/path/log.k";
//echo $file;
$handle = fopen($file, "a+");
if($handle){
echo $k;
fwrite($handle, $k."\n");
fclose($handle);
}
header("Content-Type: text/html");
echo "line 22 ".$que;
exit(0);
I've checked my apache2 error logs and none are invoked. Why is it not working in my case?
I know this is almost a year old question but I just started teaching myself Qt and I recently ran into this issue as well and was bought to this page. So for those who are also stuck on this, here is how I solved it.
First change the connect from:
connect(qnam,SIGNAL(destroyed(QNetworkReply*)),this,SLOT(read(QNetworkReply*)));
to:
connect(reply, SIGNAL(finished()), this, SLOT(onReply()));
Then add it to your code after the post call like so:
reply = qnam.post(request, json_data);
connect(reply, SIGNAL(finished()), this, SLOT(onReply()));
The finished method is part of the QNetworkReply signals and is fired when the reply is finished. The method inside of SLOT is a Q_SLOT that you have to define in your hpp. Then move your code to your onReply method it would look similar to this:
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response = reply->readAll();
if (reply)
{
if (reply->error() == QNetworkReply::NoError)
{
const int available = reply->bytesAvailable();
if (available > 0)
{
const QByteArray buffer = reply->readAll();
response = QString::fromUtf8(buffer);
// success = true;
}
}
else
{
response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
}
qDebug()<<"code: "<<reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString()<<" response: "<<response;
reply->deleteLater();
}
sources: QNetworkReply, BlackBerry Sample App Maven source code
I have made a program using PHP Script, but whenever i am trying to run my script using Browser getting Problem Loading Page:Firefox can't establish a connection to the server at 10.0.2.2.
I have saved test.php under - E:\xampp\htdocs
test.php:
<?php
$objConnect = mysql_connect("localhost","root","");
$objDB = mysql_select_db("registration_login");
$_POST["sUsername"] = "testname";
$_POST["sPassword"] = "testpassword";
$_POST["sName"] = "testname";
$_POST["sEmail"] = "testemail";
$_POST["sTel"] = "testtel";
$strUsername = $_POST["sUsername"];
$strPassword = $_POST["sPassword"];
$strName = $_POST["sName"];
$strEmail = $_POST["sEmail"];
$strTel = $_POST["sTel"];
/*** Check Username Exists ***/
$strSQL = "SELECT * FROM member WHERE Username = '".$strUsername."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
$arr['StatusID'] = "0";
$arr['Error'] = "Username Exists!";
echo json_encode($arr);
exit();
}
/*** Check Email Exists ***/
$strSQL = "SELECT * FROM member WHERE Email = '".$strEmail."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
$arr['StatusID'] = "0";
$arr['Error'] = "Email Exists!";
echo json_encode($arr);
exit();
}
/*** Insert ***/
$strSQL = "INSERT INTO member (Username,Password,Name,Email,Tel)
VALUES (
'".$strUsername."',
'".$strPassword."',
'".$strName."',
'".$strEmail."',
'".$strTel."'
)
";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
$arr['StatusID'] = "0";
$arr['Error'] = "Cannot save data!";
}
else
{
$arr['StatusID'] = "1";
$arr['Error'] = "";
}
mysql_close($objConnect);
echo json_encode($arr);
?>
I recommend you to use your machine's IP Address in place of 10.0.2.2
So complete URL should look like this:
http://ipaddress/test.php
Note: Above solution for while you want to use Local Server via Android Emulator
Do you know where the 10.0.2.2 is coming from? By default localhost resolves to 127.0.0.1. This could potentially be your problem.
The problem you are experiencing wouldn't be from your PHP script. But rather the request isn't getting from your browser to your Apache web server.
- You'll want to ensure Apache is running.
- You could try making sure you are using localhost in the URL.
- You could check the apache log files under /Xampp/apache/logs/ and see if there is any recent errors being logged.
- You could also try a tool like Fiddler to see the exact response of the request.
Hope that helps.
i my webpage when the user click forgot password button i ask email , Securitykey etc.. when the user click the sendmail button i send the email,securitykey, etc to a ajax function named 'sendmail(par1,par2,par3)' [Code is below]. The user provide Existing mailid , securitykey... , rtstr[1] is set to 1 [one] . So the 'Mail send successfully' was displayed . But if the user again enter the info [without refreshing the page]and click sendmail button, it didn't work in IE. But it works perfectly in Firefox.
var xmlhttp1;
xmlhttp1 = GetXmlHttpObject();
function sendmail(Mailforpwd, Secquestion, Secanswer) {
if (xmlhttp1 == null) {
alert("Browser does not support HTTP Request");
return;
}
var url = "SendEmail.php";
url = url + "?Email=" + Mailforpwd;
url = url + "&Squestion=" + Secquestion;
url = url + "&Sanswer=" + Secanswer;
xmlhttp1.onreadystatechange = stateChanged;
xmlhttp1.open("GET", url, true);
xmlhttp1.send(null);
function stateChanged() {
if (xmlhttp1.readyState == 4) {
var Result = xmlhttp1.responseText;
rtstr = Result.split('#');
//alert(xmlhttp1.responseText);
//alert(rtstr[0]);
//alert(rtstr[0]);
if (rtstr[0] == 1) {
document.getElementById("Errorcredentials").innerHTML = "Mail send successfully";
}
else if (rtstr[1] == 0) {
//alert(document.getElementById("Errorcredentials").innerHTML);
document.getElementById("Errorcredentials").innerHTML = "Please provide Exist information";
}
else {
document.getElementById("Errorcredentials").innerHTML = "There is a problem in sending mail, please try after sometime";
}
}
}
}
function GetXmlHttpObject() {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
Here my problem is at second time the function stateChanged() was not called , if i put a alert in this function , first time it display alert box , But next time it won't. This is my problem . The sendMail.php was called eachtime .
Whenever I have this problem it is because IE caches your AJAX request. The best way to avoid this is to append a random number as a key in your query string each time.
url = url + "&rand=" + Math.random();
Or, better, since your AJAX request appears to be causing some action to happen server-side, why don't you use HTTP POST instead of GET?
xmlhttp1.open("POST", url, true);
This is a caching problem. Append current date time to your url to make it unique.
url = url + "&rand=" + (new Date());
just swap these lines in your code.
xmlhttp1.onreadystatechange = stateChanged;
xmlhttp1.open("GET", url, true);
after fixing it looks like
xmlhttp1.open("GET", url, true);
xmlhttp1.onreadystatechange = stateChanged;
thats it!!
skypeid: satnam.khanna