简体   繁体   English

如果请求从移动应用程序发送到PHP,则HTTP_USER_AGENT的等效值应该是多少?

[英]What should be the equivalent of HTTP_USER_AGENT in case of request coming from mobile app to PHP?

I want to pass an URL to some function in PHP. 我想将URL传递给PHP中的某些函数。 My concern is related to the value of server variable $_SERVER['HTTP_USER_AGENT'] 我的担心与服务器变量$_SERVER['HTTP_USER_AGENT']的值有关

Actually when I made a request from the browser the respective function works fine but when I made a request from CURL or iOS mobile app it gives following data, in both these cases the function doesn't perform well. 实际上,当我从浏览器发出请求时,相应的功能可以正常工作,但是当我从CURL或iOS移动应用程序发出请求时,它会提供以下数据,在这两种情况下,该功能均无法正常运行。 I want the exactly equivalent value in these two requests likerequest made from browser. 我想要这两个请求中的完全相同的值,例如来自浏览器的请求。

Following are the three outputs/responses of ( echo $_SERVER['HTTP_USER_AGENT']; )from the three different requests: 以下是来自三个不同请求的( echo $_SERVER['HTTP_USER_AGENT']; )的三个输出/响应:

Response when request made from Mozilla Firefox: 从Mozilla Firefox发出请求时的响应:

Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0

Response when request made from CURL(Terminal on Ubuntu Linux): 从CURL发出请求时的响应(在Ubuntu Linux上为终端):

curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3

Response when request made from iOS app : 从iOS应用发出请求时的响应:

Campusknot/31 (iPhone Simulator; iOS 8.3; Scale/2.00)

Please help me in order to work the function from iOS app as well as from CURL, from web browser it is working fine now, so no new issues with the request made from web. 请帮助我,以便从iOS应用程序以及CURL使用该功能,现在可以从网络浏览器正常工作,因此从网络发出的请求没有新问题。 Thanks in advance. 提前致谢。

One of the option is just to specify the User Agent string, ie - curl: 选项之一只是指定用户代理字符串,即-curl:

curl -A "Desired User Agent String" google.com

and for iOS: 对于iOS:

NSMutableURLRequest *request = ...;
[request setValue:@"Desired User Agent String" forHTTPHeaderField:@"User-Agent"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM