PHP - Getting Current URL

后端 未结 3 1089
无人及你
无人及你 2020-12-05 02:19

This seems like a common questions but none of them seem to be what i\'m looking for. If there is a website:

www.example.com/test.php

I want to pu

相关标签:
3条回答
  • 2020-12-05 02:34

    This will get you the name of the file that was requested (based on the URL invoked, not real location of the file - just in case you are using mod_rewrite):

    $filename = basename($_SERVER['REQUEST_URI']);
    

    For both http://www.example.com/testing01.php and http://www.example.com/x/y/z/testing01.php will give you:

    testing01.php
    
    0 讨论(0)
  • 2020-12-05 02:55
    $file = $_SERVER["SCRIPT_NAME"];
    $break = explode('/', $file);
    $pfile = $break[count($break) - 1]; 
    
    0 讨论(0)
  • 2020-12-05 02:56
    $query = $_SERVER['PHP_SELF'];
    $path = pathinfo( $query );
    $what_you_want = $path['basename'];
    

    Voila.

    0 讨论(0)
提交回复
热议问题