【发布时间】:2017-11-02 00:04:06
【问题描述】:
我希望能够验证 cURL 请求的来源。
所以,这里是客户将使用的 api:
$url_api = 'http://apiwebsite.com/api.php';
$post_data = array(
'test' => 'test',
'test2' => 'test2',
'test3' => 'test3',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
if($output === FALSE){echo "cURL Error: " . curl_error($ch);}
curl_close($ch);
print_r($output);
然后,在 apiwebsite.com/api.php 上,我需要编写代码来验证请求的来源。
假设 website1.com 通过 curl apiwebsite.com/api.php
请求了一个代码如何验证域名真的是 website1.com ?如何只允许 api 访问这个特定的域名?
我不想要通过邮寄或任何其他方式从客户代码中发送,因为这很容易被破坏/破解。我想直接从 apiwebsite.com/api.php 代码验证请求 api 的域是否真的是 website1.com
有可能吗?
如果不是,我至少可以验证 IP 地址吗?或者跟踪名称服务器之类的东西?
谢谢。
PS:curl 传输密码安全吗?
【问题讨论】:
-
使用 htaccess 只允许 website1.com 的 IP 地址