dongyimeng3764 2012-02-04 12:15
浏览 101
已采纳

如何用PHP检测当前页面?

I need to detect page to do some styling on a website, right now I'm using

$currentpage = $_SERVER['REQUEST_URI'];

but this returns something like /development/en/contact.php
I would like something that will only return contact.php
is there a method to achieve this?

  • 写回答

4条回答 默认 最新

  • dongyi2083 2012-02-04 12:17
    关注
    basename($_SERVER['SCRIPT_NAME']);
    

    It will return only the file and strips the folders. For more information see basename()

    Note the usage of SCRIPT_NAME instead of REQUEST_URI as REQUEST_URI may contain additional "crap":

    http://example.com/dev/en/contact.php/this/is/crap
    REQUEST_URI: /dev/en/contact.php/this/is/crap
    SCRIPT_NAME: /dev/en/contact.php
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度