I have a server setup on my laptop (easyphp1) with appache and php/mysql and that is where I design then I upload to my host. So ths setups are a bit different between the two.

My problem is in the end I want my variable be..$filepath = $_SERVER['PHP_SELF']; and then be able to echo '$filepath'; within my page.
On my laptop the echo I get (which is what I want) is "/index.php". But when I upload it to my host I get "/" (slash and no filename).

I would guess this has to do with global variable? but this is just a SWAG (scientific wild ass guess).

Any ideas would be great.

Thank you

    Try using $_SERVER['SCRIPT_NAME'] instead.

    Alternatively, do a print_r($_SERVER); and look for the value you're after. More information on the different values can be found via this manual page: [man]variables.predefined[/man].

      thanks, I'll check it out.

      I was using the script_name and it works fine, but it shows a absolute file path and I would prefer a relative path to the file. Because I am moving my files from my web site to my laptop an absolute path causes problems and won't work on the laptop when I bring them from the webhost.

      Thanks again.

        Really? SCRIPT_NAME is a path relative to the URL ("/phpinfo.php" for example) on my servers. $_SERVER['SCRIPT_FILENAME'], however, is an absolute path - perhaps you were actually using this?

        If nothing else, you could always use str_replace() to remove the $_SERVER['DOCUMENT_ROOT'] from the absolute path, leaving you with a path relative to the root of your site (aka a URI).

          I have used both script name and script filename with the same results on the webhost. On my laptop server they both act as you described (correctly).

          I did the $print_r['server'] on both my laptop and my host and noticed something odd on the host maybe. I won't print the whole report but here is what $server['script_name'] shows on my host...

          [SCRIPT_NAME] => / [ORIG_PATH_TRANSLATED] => /home/mygob2/public_html/index.php

          I wonder if there is something my host has set wierd. I am not sure what the "[orig_path...' is all about. Do you think that is effecting my results?

          Thanks again for your help.

            Eh... it sounds familiar... perhaps some mod_rewrite'ing is being done?

              Write a Reply...