This code is working fine on localhost, but not on server although it is generating password on server. cURL is enabled on my server and on localhost it is sending message fine.
<?php
if(isset($_POST["submit"])){
$adm=$_POST["admno"];
$phn=$_POST["phn1"];
include("model.php");
$db = new database;
$r=$db->register($adm);
while($row=mysql_fetch_array($r)){
if($row["phn_no1"]==$phn || $row["phn_no2"]==$phn || $row["phn_no3"]==$phn)
{
$formatted = "".substr($phn,6,10)." ";
$password = $formatted + $adm;
echo $password;
$db->setpassword($adm,$password);
$pre = 'Dear%20Parents,Your%20Password%20is%20';
$suf = '%20ThankYou.CV';
$sms = $pre.$password.$suf;
$ch = curl_init("http://www.perfectbulksms.in/Sendsmsapi.aspx?USERID=ID&PASSWORD=PASS$&SENDERID=SID&TO=$phn&MESSAGE=$sms");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
$result = curl_exec($ch);
curl_close($ch);
header("Location:password.php?msg=new");
} else {
header("Location:register.php?msg=invalid");
}
}
}
?>
Related
I'm trying to implement reCAPTCHA in my website, everything seems working fine, except the return from file_get_contents().
Here is my code:
if ($_REQUEST["send"] == 1){
// access
$secretKey = 'my_key';
$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);
echo ($responseKeys);exit;
if(intval($responseKeys["success"]) !== 1) {
$message = 'Invalid reCAPTCHA';
} else {
$msg = 'content';
send_mail('send_to',"Subject",$msg);
header("location:index.php?send=1");exit;
}
}
My variable response is returning empty.
I tried to open https://www.google.com/recaptcha/api/siteverify? inserting manually the variables and it seems to work fine.
Am I forgeting something?
Thanks
Their API waiting for a POST request. Your code send GET request.
See answer here How to post data in PHP using file_get_contents?
My wrappers were disabled, reason why I couldn't reach the URL and get the return.
As I don't have access to php.ini the workaround was send the request with curl, here is the code:
$url = "https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
echo "\n<br />";
$response = '';
} else {
curl_close($ch);
}
if (!is_string($response) || !strlen($response)) {
echo "Failed to get contents.";
$contents = '';
}
$responseKeys = json_decode($response,true);
I have been looking for what I might be doing wrong and for solutions all over but none seem to rectify my problem. I have a form with a recaptcha, it is pretty simple. But my recaptcha validation fails every time and echo's "Not successful" when it should be successful. What am I doing wrong? Here is my code.
<?php
require_once('src/autoload.php');
require_once('src/ReCaptcha/ReCaptcha.php');
require_once('src/ReCaptcha/RequestMethod.php');
require_once('src/ReCaptcha/RequestParameters.php');
require_once('src/ReCaptcha/Response.php');
require_once('src/ReCaptcha/RequestMethod/Post.php');
require_once('src/ReCaptcha/RequestMethod/Socket.php');
require_once('src/ReCaptcha/RequestMethod/SocketPost.php');
require_once('src/ReCaptcha/RequestMethod/Curl.php');
require_once('src/ReCaptcha/RequestMethod/CurlPost.php');
$gRecaptchaResponse = $_POST['g-recaptcha-response'];
$remoteIp = $_SERVER['REMOTE_ADDR'];
$SITEKEY = 'XXXX';
$secret = 'XXXX';
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
echo "success";
} else {
$errors = $resp->getErrorCodes();
echo "not success";
echo $errors;
}
?>
//reCaptcha
$StrUrl = "https://www.google.com/recaptcha/api/siteverify";
$StrSecretKey = "XXXXXX";
$data = array('secret' => $StrSecretKey, 'response' => $_POST['Response']);
$ch = curl_init($StrUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$Response = curl_exec($ch);
curl_close($ch);
$Robot = json_decode($Response);
$data = 0;
if(isset($Robot->success) AND $Robot->success==true){
//CODE
}
Try this. It was originally designed for an AJAX call, however if you change the $_POST['Response'] to the name of the response variable then it should work, hopefully.
I'm trying to access the PayPal ButtonManager API. I'm getting error 10002, Authentication failed. I've double/triple checked all the credentials, and regenerated them too. I don't think the AppID should be necessary; it doesn't work with or without it anyway.
Exact error message text:
L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication/Authorization Failed&L_LONGMESSAGE0=You do not have permissions to make this API call&L_SEVERITYCODE0=Error
//ButtonManager API
$ret = ch_post();
error_log($ret);
echo urldecode($ret);
function ch_post(){
//API Credentials
$accID = urlencode("accID");
$username = urlencode("username_api1.website");
$password = urlencode("password");
$signature = urlencode("signature");
$appID = urlencode("APP-ID");
$endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$certpath = "C:\certpath.pem";
$ch_headers = array(
"USER"=>$username,
"PWD"=>$password,
"SIGNATURE"=>$signature,
"APPID"=>$appID,
"VERSION"=>"51.0"
);
$ch_params = array(
"METHOD"=>urlencode("BMCreateButton"),
"OTHERPARAMS"=>urlencode("OTHER")
);
$ch = curl_init($endpoint);
curl_setopt($ch,CURLOPT_HTTPHEADER,http_build_query($ch_headers));
curl_setopt($ch,CURLOPT_CAINFO,$certpath);
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($ch_params));
curl_setopt($ch,CURLOPT_POST,TRUE);
curl_setopt($ch,CURLOPT_HEADER,TRUE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch,CURLOPT_SSLVERSION, 6);
$cexec = curl_exec($ch);
if(!$cexec) {
$response = "Failed: ".curl_error($ch)."(".curl_errno($ch).")";
curl_close($ch);
return $response;
}
curl_close($ch);
return $cexec;
}
Hello I use this curl for site http://ip-whois.net but if I debug in my local comp I harcode $ip = "176.241.128.140"; - this my ip that I was given by my provider and I have $out = false, why ???
echo curl_error ($curl); = "Empty reply from server". I try this site http://www.ip-whois.net/ in browser and not work, what are the analogy this site who work with curl_setopt($curl, CURLOPT_URL, 'http://ip-whois.net/ip_geo.php?ip='.$ip); ?
how to do this right ?:
$ip = $request->getClientIp();//I hard code $ip = "176.241.128.140"
$record = $hAid->getInfoIpCity($ip);
if ( $curl = curl_init() ) {
curl_setopt($curl, CURLOPT_URL, 'http://ip-whois.net/ip_geo.php?ip='.$ip);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
$out = curl_exec($curl);
$matches = array();
$country = preg_match_all("/Страна: (.*)/i", $out, $matches);
print_r($matches[1][1]);
curl_close($curl);
}
i am totaly new to CURL thing . i have a problem .
i have the below script which supposed to get remote files using a proxy , i am trying this code on my local host machine and it is working great "done successfully part: .
when i run it from server , it just keep going to the "invalid proxy" although it is same proxy as used in the local host ..
<?php
$dots = '';
include($dots.'classes/config.php');
$wordsLimitPerCall = 1;
$maxAttemptsTrials = 3;
$timeout = 10; // Seconds
$proxy = sqlSelectRow('proxy', array(
'condition'=>'not_valid=0',
'order'=>'rand()'
));
echo '<ul>';
if($proxy)
echo '<li>Using proxy: '.$proxy['proxy'].':'.$proxy['port'].'</li>';
$wordsRes = sqlSelectRows('words', array(
'condition'=>'is_done=0 and trials<'.$maxAttemptsTrials,
'limit'=>$wordsLimitPerCall,
'order'=>'created asc'
));
while($arr = $wordsRes->fetch_assoc()) {
$word = urlencode($arr['word']);
$url = 'http://example.com'.$word;
$callSettings = array(
'method'=>'curl',
'timeout'=>$timeout
);
if($proxy)
$callSettings['proxy'] = $proxy['proxy'].':'.$proxy['port'];
$result = callRemoteURL($url, $callSettings);
$filename = urldecode($word);
$filename = 'file/'.$arr['id'].' - '.$filename.'.mp3';
echo '<li>Getting the word: '.$word.'</li>';
if($result && strpos($result, '<html')===false) {
if(file_exists($dots.$filename))
unlink($dots.$filename);
fileWrite($filename, $result);
$is_done = 1;
echo '<li>done successfully</li>';
}
else {
$is_done = 0;
if($proxy) {
sqlUpdate('proxy', array(
'not_valid'=>0
), array(
'condition'=>'id='.$proxy['id']
));
echo '<li>Proxy is not valid</li>';
}
}
sqlUpdate('words', array(
'trials'=>$arr['trials']+1,
'path'=>$url,
'last_call_date'=>date('Y-m-d H:i:s'),
'is_done'=>$is_done
), array(
'condition'=>'id='.$arr['id']
));
}
echo '</ul>'; ?>
below the function called from utils
<? php
if($set['method']=='curl' && extension_loaded('curl'))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, $set['timeout']); // Seconds
if($set['proxy'])
curl_setopt($ch, CURLOPT_PROXY, $set['proxy']);
ob_start();
if(curl_exec($ch) === false)
{
$errorNo = curl_errno($ch);
if($errorNo==28)
print_r('The connection took time more than '. $set['timeout'].' seconds, so we disconnected the process');
else
if($errorNo!=7)
print_r(curl_error($ch));
$result=false;
}
else
{
$result = ob_get_contents();
}
ob_end_clean();
return $result;
}
?>
sorry if its too long ... but i've spent the last couple days tryng to find out . any idea or what shall i do ?