SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,099
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Current template/file path

    How do I get the current template/file path. I was always usin Coldfusion where I could use:
    Code:
    <cfset currentPage = GetFileFromPath(GetTemplatePath())>
    to determine the current template/file path. How would I do something similar in PHP?

    Thank you all in advance!
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  2. #2
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,099
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found out that $_SERVER['PHP_SELF'] and $_SERVER['REQUEST_URI'] are coming very near to what I am looking for. Only not completely. This is the situation: I am working on a Multi-lingual Website, where each language is located in its own directory e.a. en, it, es, nl etc.. So when I'm on the english version (en/index.php) of the site and I click the Italian flag, I should be redirected to index.php in the Italian directory (it/index.php) so I tried:
    Code:
    <?php
    $current_path = $_SERVER['PHP_SELF'];
    
    echo "<a href='../it$current_path'>IT</a>";
    ?>
    But this way the directory (en) holding index.php is included in the url as well:
    Code:
    sitename.com/it/en/index.php
    Where I actualy need:
    Code:
    sitename.com/it/index.php
    What should I use to get just the current filename (index.php) without the directory (en) holding that file?

    Thank you in advance!


    Edit: Sollution found!!! Instead of using:
    Code:
    $current_path = $_SERVER['PHP_SELF'];
    I had to use:
    Code:
    $current_path = basename($_SERVER['PHP_SELF']);
    Last edited by donboe; Mar 5, 2014 at 04:47. Reason: Sollution found
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •