SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru cyjetsu's Avatar
    Join Date
    May 2008
    Posts
    814
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    detect requesting file and

    In php is there a function to detect which file requested the current one?

    For example I need to include a php file(global.php) in all my webpages(index), but in that file(global) I want the content of the file requesting it(index) to be inserted in the middle of global.php. This is for index being page content, and global being the outer html shell surrounding content(html shell same for every page). At the moment I have global.php split in 2 parts/files and simply requesting global-part1.php, then displaying content then requesting global.part2.php

    Also I need the same function for having a unique css file per webpage type(as well as global.css). At the moment in global-part1.php I have
    <link rel="stylesheet" type="text/css" href="<?php echo $substyle ?>"/>
    Then in index.php I put the location of the unique stylesheet as a variable.

    So you can see I need a function in global.php which detects the location of the file requesting it(which index page), to determine what files need to be gotten. Although maybe for the second part(css), it would be better having it as I do now, since dozens of webpages(of the same type) will share the same css file so having the cssfile as a variable in each index would be simpler than having a massive eleborate function in global.

    Or maybe there is another method I don't know about? any ideas?

  2. #2
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I follow you correctly, you can get the requested file through $_SERVER['PHP_SELF']. there is also $_SERVER['REQUEST_URI']

    Then you can just work based off that...
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  3. #3
    SitePoint Guru cyjetsu's Avatar
    Join Date
    May 2008
    Posts
    814
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That makes sense. So since I include the file with the function 'self', the requesing file is the file 'self' is performed on. For some reason I was thinking a function would have to be executed before the file was inserted.

    So how would I use this to unscatter my global html shell surrounding content?


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
  •