SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File Path Question

    Hi all,

    I am working out the path to an app, in a config file, and, I need a halfway house between two solutions, which I can't find (or can't think of ).
    First of all, I started off with this:
    PHP Code:
    $path dirname(__FILE__); 
    This was OK, and did the job for the PHP files, but gave me a long string like /home/adamc/public_html/path/to/my/file
    I then went and tried this:
    PHP Code:
    $path dirname($_SERVER['SCRIPT_NAME']); 
    which only returned /path/to/my/file

    I thuoght great, but then realized something. One of the reasons I need these paths is that I use URL rewriting, and the end user can bury this app down as many directory's as they want! So, My final example would even return my re-written path, which defeated the object! I need something that will work in HTML links, that stays as the root folder of my application (which $_SERVER['SCRIPT_NAME']) would do, except, as the file needs to be included, it changes to reflect that of the file that's called it! So, is there a way to leave this value in concerete, so it can't change, or is there a function etc. I am missing?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    File paths and url's don't always map to each other, so you should use a different variables if you want reliability and flexibility.

  3. #3
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, you are very correct with that.
    So, onto your point, is there a way of finding out what I want, or is that just wishful thinking?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, there's $_SERVER['PHP_SELF']. Be aware though that depending on webserver config, this variable can be manipulated via the url, which can facilitate certain types of xss attacks.

    Consider just having the user enter the base url path in the config file, then your app can just append relative url paths to that value.

  5. #5
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, I don't really want the user to have to faf about with the cnofig file. I know I've said this before, but blogging systems such as WordPress, TextPattern, Expression Engine (I could go on) manage to support this type of thing O.T.B, without changing any config. I was wandering what sort of methods they used to do this, and wether I could use a similar approach? I was thinking about capturing it during the install, or similar.


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
  •