如何能在不动安卓 和 苹果版本的前提下 php接口这边判断调用这个接口的是安卓还是苹果?
回复讨论(解决方案)
function get_device_type(){ $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $type = 'other'; if(strpos($agent, 'iphone') || strpos($agent, 'ipad')){ $type = 'ios'; } if(strpos($agent, 'android')){ $type = 'android'; } return $type;}
function get_device_type(){ $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $type = 'other'; if(strpos($agent, 'iphone') || strpos($agent, 'ipad')){ $type = 'ios'; } if(strpos($agent, 'android')){ $type = 'android'; } return $type;}首先谢谢你的回答 这个好像对浏览器可以 但是如果安卓或者苹果调用我这个接口 通过上述方式应该没办法知道 是安卓或者苹果吧
你可以在接口地址上带个参数,例如安卓 device_type=1;苹果device_type=2,附带一些加密措施,防止从其它PC或设备访问时参数判断失误
让客户端每次请求的时候带个标识参数就好了。
你只能在客户端, 也就是安卓与苹果端对 用户标识区分
如
Http.setRequestProperty("User-Agent","Mozilla/5.0 Android");
function get_device_type(){ $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $type = 'other'; if(strpos($agent, 'iphone') || strpos($agent, 'ipad')){ $type = 'ios'; } if(strpos($agent, 'android')){ $type = 'android'; } return $type;}首先谢谢你的回答 这个好像对浏览器可以 但是如果安卓或者苹果调用我这个接口 通过上述方式应该没办法知道 是安卓或者苹果吧
。。这个是判断浏览器的。。 在接口中调用 一般都是在客户端传递的参数中标识。
你可以在接口地址上带个参数,例如安卓 device_type=1;苹果device_type=2,附带一些加密措施,防止从其它PC或设备访问时参数判断失误
谢谢你的回答 如果在客户端传参数 就得改App 能不能再不动用客户端的情况下 知道调用接口的是安卓 或者 ios应用发出的请求不像浏览器带useragent,目前不知道有什么办法区分,我这边工作也会用到,这两天研究下
应用发出的请求不像浏览器带useragent,目前不知道有什么办法区分,我这边工作也会用到,这两天研究下
用fiddler截了下自己手机的数据包,居然真的带了useragent
不确定这个agent是开放权限给开发者自定义,还是安卓java虚拟机封装成私有的
不确定是否乱七八糟的安卓机型都能带上
截一下IOS和windows phone的看看吧
?用API??????,使用user-agent不?的。
有个Mobile Detect的PHP类,你可以研究一下
谢谢大家的热心回答

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
