简体   繁体   English

如果我在另一页上包含php脚本,如何检测当前URL的名称?

[英]How can I detect the name of my current URL if I include my php script on another page?

This is my home.php : 这是我的home.php

require('header.php');

This is my header.php 这是我的header.php

if (basename(__FILE__) == "home.php"){
        echo "you are on home.php"; 
} else {
        echo "you are not on home.php";
}

When I now open the URL www.mypage.com/home.php I see the text you are not on home.php 当我现在打开URL www.mypage.com/home.php我看到you are not on home.php

Try something like this 试试这个

<?php
    $explode = explode("/", $_SERVER['REQUEST_URI']);
    $explode = explode("?", $explode[count($explode)-1]);

    echo $explode[0];

暂无
暂无

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

相关问题 Facebook php-如何检测喜欢我页面的人 - Facebook php - How can I detect people like my page 如何获取PHP中当前包含脚本的URL? - How do I get the url of the current include script in PHP? 如果要包含的文件位于当前PHP文件的文件夹之外,如何包含PHP文件 - How can I include PHP files if the file that I'm going to include is located outside the folder of my current PHP file 如何在Wordpress中更改页面名称? 我需要编辑URL .htaccess吗? - How can I change my page name in Wordpress? Do I need to edit my URL .htaccess? 我可以将CURL库作为类包含在我的PHP脚本中吗 - Can I include CURL library in my PHP script as a class 如果当前表单中的表单字段不在当前表单中,如何在其中添加表单字段? - How can I include a form field in my POST if it is not in the current form? 我当前的PHP脚本重定向到白页。 如何告诉我的脚本重定向到其他位置? - My current PHP script redirects to a white page. How do I tell my script to redirect to a different location? 如果我的表单操作指向另一个页面,如何从当前页面获取帖子值? - How can I get post value from current page if my form action point to another page? 如何编辑我的入队脚本函数以包含 Internet Explorer 和页面模板样式表? - How can I edit my enqueue script function to include Internet Explorer and page template stylesheets? Wordpress:如何获取页面的当前名称 - Wordpress: How do I get the current name of my page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM