Re: __FILE__ vs. $_SERVER['DOCUMENT_ROOT'] ?

From: randy (sesser_at_gmail.com)
Date: 02/07/05


Date: 7 Feb 2005 07:34:12 -0800

If your host is using any symbolic links (which I suspect they are),
realpath() will resolve those symbolic links. I'm guessing this is
what's causing the discrepency. I'm just using dirname(__FILE__) to set
a constant for the script root. It seems to work well so far. The only
downside to this is that you have have the __FILE__ in the root of your
application.

hth
r.

Tom wrote:
> I'm trying to dynamically adjust the path for one of my scripts using
> this:
>
> $script_path = str_replace( $_SERVER['DOCUMENT_ROOT'], "",
> dirname(realpath(__FILE__)) ) . DIRECTORY_SEPARATOR;
>
> The problem: the server I'm currently testing it on returns for
> $_SERVER['DOCUMENT_ROOT'] something like the path "home/user/path/"
and
> for __FILE__ "home2/user/path/scriptdir/" I tried to trace the
> discrepancy running phpinfo, but the only reference I can find to
> "home2" there is _ENV["PWD"].
>
> Anyway, this is throwing all my best laid plans into confusion. Can
> someone help me understand why $_SERVER['DOCUMENT_ROOT'] and __FILE__
> are returning different basepaths?
>
> And how I might get my script to do what I'd like it to do
(basically,
> return the directory path of my script minus the document root so
that
> I can then append it to the absolute URL)?
>
> Hope this makes sense. Thanks,
>
> Tom



Relevant Pages

  • Re: Solaris Security Script
    ... xyberpix wrote: ... > I'm working on a rather large Solaris security script, ... > - Search for symbolic links ... > is to run this script as root, so that as much information as possible can ...
    (Focus-SUN)
  • Solaris Security Script
    ... I'm working on a rather large Solaris security script, ... - Search for symbolic links ... is to run this script as root, so that as much information as possible can ...
    (Focus-SUN)
  • IBM Informix Web DataBlade: Local root by design
    ... IBM Informix Web DataBlade: Local root by design ... Impact: Any user who can: 1) Save a Perl script anywhere on the server's ... admin right on any database can do it by loading the WDB module into ...
    (Bugtraq)
  • RE: Linux hacked
    ... I would also suggest using a simple script in the future that alerts ... Subject: Linux hacked ... To get back into your account you want to use, at the boot manager ... boot normally and you should be able to login as root with your new ...
    (Security-Basics)
  • Re: BSDstats v3.0 - The Security Rewrite
    ... The bsdstats script could easily pick up that entry and set ... a management machine, and that management machine only has ... Email is sent to root containing IDTOKEN= as generated by host, root forwards that to rpt@xxxxxxxxxxxx, rpt@xxxxxxxxxxxx sends back KEY= value ... second time, submits report values to root, root forwards that to rpt@xxxxxxxxxxxx ... ...
    (freebsd-questions)