Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用api键参数通过使用curl的手动api键发布json数据_Php_Mysql_Api_Curl - Fatal编程技术网

Php 如何使用api键参数通过使用curl的手动api键发布json数据

Php 如何使用api键参数通过使用curl的手动api键发布json数据,php,mysql,api,curl,Php,Mysql,Api,Curl,如何使用curl和api键参数插入json post数据 在下面的代码中,我试图在url中添加一个apikey参数 index.php: $data = array( // 'name' => '100236', // 'age' => '265', 'nric' => '123546', 'id' => '266', 'fullname'=>'sairam', 'gender' => 'M', 'pa

如何使用curl和api键参数插入json post数据

在下面的代码中,我试图在url中添加一个apikey参数

index.php:

$data = array(
    // 'name' => '100236',
 //    'age' => '265',
    'nric' => '123546',
    'id' => '266',
    'fullname'=>'sairam',
    'gender' => 'M',
    'password' => '123546',
    'address'=>'jlnklmanalpoi',
    'postcode' => '502103',
    'state' => 'telangana',
    'contact1'=>'+60123654',
     'email' => 'email@email.com',
    'rank'=>'AM',
   'expirydate'=>'14-07-2017'

);
  $post_json = json_encode($data);

          $api_key = '99999your9999api999keyd4eae7c3';    
       $endpoint = 'http://localhost/apib/data.php?key=.$api_key ';
        $ch = @curl_init();
        @curl_setopt($ch, CURLOPT_POST, true);
        @curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
        @curl_setopt($ch, CURLOPT_URL, $endpoint);
        @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = @curl_exec($ch);
        $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curl_errors = curl_error($ch);
        @curl_close($ch);
        echo "curl Errors: " . $curl_errors;
        echo "\nStatus code: " . $status_code;
        echo "\nResponse: " . $response;
?>

am unable to use api key below page :
这是end point data.php

$_POST = json_decode(file_get_contents('php://input'), true);


if (isset($_POST['nric'],$_POST['id'],$_POST['fullname'],$_POST['gender'],$_POST['password'],$_POST['address'],$_POST['postcode'],$_POST['state'],$_POST['contact1'],$_POST['email'],$_POST['rank'],$_POST['expirydate'])) {

 global $db;
$db = mysqli_connect("localhost", "root", "", "ilde");
if($db === false)
{

    die("ERROR: Could not connect. " . mysqli_connect_error());
}

    $nric=mysqli_real_escape_string($db,$_POST["nric"]);
    $id =(int)$_POST["id"];
     $fullname=mysqli_real_escape_string($db,$_POST["fullname"]);
      $gender=mysqli_real_escape_string($db,$_POST["gender"]);
我想手动将安全url与apikey一起使用。请帮助我解决此问题。如何使用curl和api key参数插入json post数据。请帮助我,下面是我的代码,我正在尝试在url中添加apikey参数

$endpoint = 'http://localhost/apib/data.php?key='.$api_key.' ';

更改$endpointhttp://localhost/apib/data.php?key=.$api_key';至$100http://localhost/apib/data.php?key=“.$api_键;好的。但在data.php文件中,如何编写api_密钥是否匹配?您可以通过$_GET['key']检索密钥;在data.php$api_key='9999your999api999keyd4eae7c3'中;这是一个api key data.php,使用该key index.php提供给index.php。php需要将数据推送到data.php。所以现在我们需要$api_key='99999 your999api999keyd4eae7c3';在data.php中??我已经提到,您可以通过data.phpokay中的$api_key=$_get['key']来获得它。但是我刚刚在index.php中手动分配了api key,它应该也与in data.php匹配。但是我可以在data.php中写入吗?即使我输入不同的key,它也可以工作,但我需要唯一的api key。请帮助我