如何限制 cURL 连接
我编写了一个小脚本来通过 cURL 连接到我的 API,但是,我需要知道如何限制传入的 cURL 连接以防止垃圾邮件。
这怎么能做到呢?
<?php
function shorten_url($urltoshorten) {
$url = 'http://nn.pe/api.php?url='.$urltoshorten;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
// what to post
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>
i have written a small script to connect via cURL to my API, however, i need to know how i can limit incoming cURL connections to prevent spam.
How can this be done?
<?php
function shorten_url($urltoshorten) {
$url = 'http://nn.pe/api.php?url='.$urltoshorten;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
// what to post
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用:
curl_set_opt(CURLOPT_MAXCONNECTS, 10);
来限制您通过curl建立的连接。或者您可以创建一个表并记录请求连接的 IP。希望这有帮助。
You can use:
curl_set_opt(CURLOPT_MAXCONNECTS, 10);
for limiting connections you made by curl. Or you can create a table and keep record of IPs requesting for connections.Hope this helps.