Exforsys
+ Reply to Thread
Results 1 to 3 of 3

Get Pagename From URL

This is a discussion on Get Pagename From URL within the PHP forums, part of the Programming Talk category; hi, How to get the page name from the Url.For Example My urls is like exforsys . com/viewtopic.php Then how ...

  1. #1
    Surya100 is offline Junior Member Array
    Join Date
    Apr 2009
    Answers
    7

    Get Pagename From URL

    hi,

    How to get the page name from the Url.For Example My urls is like exforsys . com/viewtopic.php

    Then how to get page name viewtopic.php. How can i do that?

    Thanks,
    Surya


  2. #2
    megabyte is offline Junior Member Array
    Join Date
    Nov 2006
    Answers
    23
    Use this basename() on the path.

    Example :

    <?php
    $path = "/home/httpd/html/index.php";
    $file = basename($path); // $file is set to "index.php"
    $file = basename($path, ".php"); // $file is set to "index"
    ?>



  3. #3
    steve.zaptech is offline Junior Member Array
    Join Date
    Jan 2010
    Answers
    2

    You can try following function to get the page name from the url....

    The following code will first get the whole url and finally you will get the page name.......

    <?php
    function currentPageURL() {
    $curpageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {$curpageURL.= "s";}
    $curpageURL.= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
    $curpageURL.= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
    $curpageURL.= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    $file = basename($curpageURL);
    return $file;
    }

    echo currentPageURL();
    ?>


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...