douqian4411 2015-12-02 09:25
浏览 93
已采纳

检测:来自curl或浏览器

I've got an almost empty page that I need for a curl. The thing is that it is also accessible by a browser and looks weird.

Is it possible in PHP to detect if the request come from a browser or a curl ? So that way I can make a redirect if it comes from browser.

Thank you.

  • 写回答

2条回答 默认 最新

  • douao1959 2015-12-02 09:29
    关注

    This will get you the client Agent, among other stuff. If your curl does not pretend to be something else, it should do.

    foreach (getallheaders() as $name => $value) {
        echo "$name: $value
    ";
    }
    

    or simpler: $_SERVER['HTTP_USER_AGENT']

    gets you the user-agent (browser signatur) directly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题