0

I just played with PHP Curl for the first time and wrote a sample code, but I don't know how to pass the parameters in the URL correctly.

Remote Site Code:

if(isset($_REQUEST['updateme']))
{

$license = $Gauntlet->filter($_REQUEST['licensekey']); 
$domainnew = $Gauntlet->filter($_REQUEST['domainnew']);
$domainold = strtolower($_SERVER['REMOTE_ADDR']);


$sqlcheckexist = "SELECT * FROM licenses WHERE licensekey = '$license' AND host = '$domainold' AND status = 'active'";
$querycheck = $DatabaseHandler->query($sqlcheckexist);

if($querycheck)
{

if($querycheck->num_rows < 1){

   $json['status'] = 301;
   $json['message'] = 'Wrong Domain or License'; 
}else{
$sqlupdate = "UPDATE licenses SET host = '$domainnew', status = 'active' WHERE licensekey = '$license'";

$json['message'] = 'Success!'; 

}
}
}

Remote Site API Url: mydomain.com/myapi/

How can i do this REQUEST in Url with parameters if i POST licensekey and domainnew and Update my Database value?

tonyleee4
  • 13
  • 2
  • Hi, becarfull you have a lot of SQLinjection in your code take a look here : https://owasp.org/www-community/attacks/SQL_Injection and use Prepare request in PHP – Inazo Feb 21 '20 at 09:54
  • 1
    Thanks for the Info, i just learning:) – tonyleee4 Feb 21 '20 at 09:55
  • Does this answer your question? [PHP + curl, HTTP POST sample code?](https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code) – Cray Feb 21 '20 at 11:46

1 Answers1

0

You can post value using php curl like this

      $payload=array();
      $payload['licensekey']='abc';
      $payload['domainnew']='123';
      $payload['updateme']='update';

      $payload=json_encode($payload);

      $ch = curl_init($url); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
      curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
      curl_setopt($ch, CURLOPT_POSTREDIR, 3);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $res=curl_exec($ch);
Jon
  • 145
  • 3
  • 9
  • And in browser URL like: `mydomain.com/myapi/?` for testing? – tonyleee4 Feb 21 '20 at 09:56
  • If you want to send values with url using curl. `$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'http:/mydomain.com/myapi/?licensekey=1111&domainnew=222&updateme=1'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch);` – Jon Feb 21 '20 at 10:06