0

Why does an URL like http://192.168.1.116/wordpress/wp-content/themes/bktf/frameworks/back-end/theme-options/options/fields/font/field_font.js.php?ver=1358535557

...ends up serving /wordpress/wp-content/themes/bktf/frameworks/back-end/theme-options.php/options/fields/font/field_font.js.php (this is also the content of `$_SERVER['PHP_SELF']).

...in the context of having both a dir name theme-options and a file name theme-options.php in the same back-end parent dir?

Also, the content of $_SERVER['SCRIPT_NAME'] is /wordpress/wp-content/themes/bktf/frameworks/back-end/theme-options.php.

Why does Apache or the PHP module automatically add .php at the end of a directory name just because there is a scrip with the same as the dir???

Note: I am using the default configuration for Apache and PHP for Ubuntu 12LTS server, installed via tasksel and then upgraded to PHP 5.4 with the https://launchpad.net/~ondrej/+archive/php5 PPA, with all the configuration files mostly identical with the defaults/examples - it's a basic LAMP server meant to run in a VM for dev purposes.

NeuronQ
  • 7,527
  • 9
  • 42
  • 60

4 Answers4

1

PHP_SELF refers to the file being run on the server, not the current url. Read the PHP $_SERVER manual for more info: http://php.net/manual/en/reserved.variables.server.php

Try $_SERVER['REQUEST_URI'] instead. That will give you the query string at the end.

Eric
  • 907
  • 7
  • 13
  • I know that! That's the point actually, the file being run on the server, $_SERVER['PHP_SELF'] has `.../theme-options.php/...` in itr's path while the URL has `.../theme-options/...`. The server just adds a ".php" tot a dir name in the URL, just because there is a script with the same name as the dir! And my only reaction to this isL WhyTF?! – NeuronQ Jan 18 '13 at 20:12
  • Is the script working? Or is this causing it to fail? I know wordpress has htaccess rules for dealing with files vs. directories. That is probably where the redirect is happening. – Eric Jan 18 '13 at 20:16
  • nope, there's no .htaccess so it doesn't seem to be a redirection problem... the only related thing I found after some googleing is http://wiki.apache.org/httpd/DirectoryAsScript but it doesn't seem to apply for my proble... – NeuronQ Jan 18 '13 at 20:27
  • Hrm... usually wordpress generates an htaccess file, is it hidden by any chance? (files beginning with a . are normally hidden by default) – Eric Jan 18 '13 at 20:37
  • no, no .htaccess file... but I figured out what was happening... sorry for the "complicated" way of describing the problem in the question – NeuronQ Jan 19 '13 at 09:25
0

PHP_SELF = The filename of the currently executing script, relative to the document root. SCRIPT_NAME = The current script's path.

Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
  • see comment to Eric's answer... maybe I phrased the question a bit awkwardly, but my problem is not about the $_SERVER vars, it's about the server serving a script with GET arguments intead of following along the directories in the URL... – NeuronQ Jan 18 '13 at 20:16
0

OK, the my question was a bit confusing, so I can understand why everyone answered a different question then the one I asked.

Anyway, what was happening in my case was that there was no theme-options dir (renamed it and forgot) and Apache translated requests like /[...]/theme-options/[...] to /[...]/theme-options.php/[...] because there was a theme-options.php script.

I still don't know why an Ubuntu LAMP setup with all the default config does this weird path juggling, but I solved my immediate problem.

NeuronQ
  • 7,527
  • 9
  • 42
  • 60
0

Apache translates requests to certain file with extension because of enabled MultiViews option: http://httpd.apache.org/docs/2.2/mod/mod_negotiation.html#multiviews