如何返回特定的信息当用户使用CURL? [英] How to return specific info when a user uses CURL?

查看:150
本文介绍了如何返回特定的信息当用户使用CURL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何在用户对我的网页人使用卷曲返回一个特定的信息(即我不想卷曲下载所有code)。我见过这样一个工作的例子上ifconfig.me,当你袅袅ifconfig.me它只返回您的IP地址。这是用Apache做,重定向卷曲用户代理或者通过某种方式PHP实现/ HTML?

解决:
感谢@Dancrumb指着我在正确的方向。我可以使用Apache的mod_rewrite卷曲用户代理重定向到一个自定义的页面,我想卷曲拉具体的信息。

  RewriteEngine叙述上
的RewriteCond%{HTTP_USER_AGENT} ^卷曲/ *
重写规则^ /指数\\ $ .PHP /ip.php [L]


解决方案

ifconfig.me,最有可能的,使用用户代理字符串,在标题中,要弄清楚这是不是一个浏览器请求。

如果您执行:

 卷曲ifconfig.me/ua

 卷曲/ 7.27.0

(或一些其它版本字符串)。

所以,如果你检查在HTTP请求的User-Agent 头,你可以看到,如果请求是一个卷曲的请求,浏览器请求或其他一些UA。

I am trying to figure out how to return a specific piece of information when a user uses cURL on one of my web pages(i.e. I don't want curl to download all code). I've seen a working example of this on ifconfig.me, when you curl ifconfig.me it returns only your IP address. Is this done with Apache and redirecting the cURL user-agent or accomplished somehow through PHP/HTML?

Solved: Thanks to @Dancrumb for pointing me in the right direction. I was able to use Apache mod_rewrite to redirect curl user-agents to a custom page with the specific information I wanted curl to pull.

RewriteEngine  on
RewriteCond %{HTTP_USER_AGENT}  ^curl/*
RewriteRule ^/index\.php$ /ip.php [L]

解决方案

ifconfig.me, most likely, uses the User Agent string, in the header, to figure out that this is not a browser request.

If you execute:

curl ifconfig.me/ua

you get

curl/7.27.0

(or some other version string).

So, if you check the User-Agent header in the HTTP request, you can see if the request is a Curl request, a browser request or some other UA.

这篇关于如何返回特定的信息当用户使用CURL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆