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?

3
  • Hi, becarfull you have a lot of SQLinjection in your code take a look here : owasp.org/www-community/attacks/SQL_Injection and use Prepare request in PHP Commented Feb 21, 2020 at 9:54
  • 1
    Thanks for the Info, i just learning:) Commented Feb 21, 2020 at 9:55
  • Does this answer your question? PHP + curl, HTTP POST sample code? Commented Feb 21, 2020 at 11:46

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

And in browser URL like: mydomain.com/myapi/? for testing?
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);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.