Ticket #114 (closed defect: fixed)

Opened 3 years ago

Last modified 7 months ago

$config[embedded] = 1 even when just running Plogger not embedded in anything.

Reported by: mwaldtha@… Owned by: kasper
Priority: normal Milestone: 1.0
Component: General Version: 1.0b3
Severity: normal Keywords: embedded
Cc: mwaldtha@…, derek@…

Description

I'm working with the beta 3 files, and I noticed that the <title> element was not being written to the <head> element, so I went to find out why. After a short search I found that in the plog-load_config.php file the following 'if' statement is being evaluated to true, and thus $config[embedded] is being set to 1, as if Plogger was being run embedded instead of standalone:

if (dirname(__FILE__) != dirname(realpath($_SERVER["PATH_TRANSLATED"])) && strpos($_SERVER["PATH_TRANSLATED"],"admin") === false) {
    $config["embedded"] = 1;
    // disable our own cruft-free urls, because the URL has already been processed
    // by WordPress
    $config["use_mod_rewrite"] = 0;
} else {
    $config["baseurl"] = "http://".$_SERVER["SERVER_NAME"]. substr($_SERVER["PHP_SELF"],0,strrpos($_SERVER["PHP_SELF"],"/")) . "/"; 

};

If I change the last conditional test from 'false' to 'true', the else branch is executed and the <title> element is written to the <head> element, and the cruft-free urls are generated (if turned on from the admin area). I'm sure this is not the propper fix, but I tested it to make sure it worked in my environment. The values being used for the 'if' statement in my environment are as follows:

dirname(__FILE__) = "/www/t/thespokenwhe/htdocs/pb3"
dirname(realpath($_SERVER["PATH_TRANSLATED"])) = "/www/t/thespokenwhe/htdocs"
strpos($_SERVER["PATH_TRANSLATED"],"admin") = ""

If you need any more information or would like for me to test a fix please let me know. :-)

Change History

Changed 3 years ago by derek

  • cc mwaldtha@…, derek@… added

Interestingly, I'm not running B3 embedded (ie. index.php is the default in the Plogger folder), but because of my vserver setup, my dirname(__FILE__) is /home/danielro/danielroyer.ca/index.php while my $_SERVER["PATH_TRANSLATED"] is /home/.antigone/danielro/danielroyer.ca. So this method of comparing one to the other is likely to cause problems.

mwaldtha@…: I believe you are running Beta 3 embedded; if $_SERVERPATH_TRANSLATED? is /htdocs, and Beta 3 is installed in /htdocs/pb3, Plogger is not being called from its own directory.

Changed 3 years ago by mwaldtha@…

Well, I am running Plogger from a subdirectory, but not embedded. To access the gallery I go to "mysite.com/dev/pb3/" and the admin interface is at "mysite.com/dev/pb3/admin/". I think the problem (at least in my environment) may come from using the "dirname" function. For example, I printed out these results:

realpath($_SERVER["PATH_TRANSLATED"]): /www/t/thespokenwhe/htdocs/dev/pb3
dirname(realpath($_SERVER["PATH_TRANSLATED"])): /www/t/thespokenwhe/htdocs/dev

This is the correct behavior of "dirname" according to the PHP manual, so removing it from the if statement and just using "realpath", the statement is evaluated correctly. I don't know if this is the right solution for all environments, but it works for mine.

- Marc

Changed 9 months ago by kasper

  • keywords embedded added
  • owner changed from mike to kasper
  • severity changed from major to normal

PATH_TRANSLATED is deprecated.

At my Unix Apache Plesk host PATH_TRANSLATED does not work for me at all, it is empty, and realpath clears the string in $_SERVERSCRIPT_NAME?.

dirname: /var/www/vhosts/baneblade.dk/httpdocs/plogger
$_SERVER["SCRIPT_NAME"]: /plogger/index.php
realpath($_SERVER["SCRIPT_NAME"]): 

So removing dirname does not change anything for me.

As a work-around you may with version 3.1, now force embedded on or off, by setting this constant in plog-config.php:

define("PLOGGER_EMBEDDED","") // 1/0 (True/False) if set will overrule automatic check

- Kasper

Changed 8 months ago by sidtheduck

I ran into this and I'm just wondering if the predefined $_SERVER variable was mistyped. Shouldn't it be:

if (dirname(__FILE__) != dirname(realpath($_SERVER["SCRIPT_FILENAME"])) && strpos($_SERVER["SCRIPT_FILENAME"],"admin") === false) {

instead of:

if (dirname(__FILE__) != dirname(realpath($_SERVER["SCRIPT_NAME"])) && strpos($_SERVER["SCRIPT_NAME"],"admin") === false) {

My edited code uses SCRIPT_FILENAME instead of SCRIPT_NAME. The way I always understood it was SCRIPT_NAME is the currently running script relative to the root and SCRIPT_FILENAME is the absolute path to the currently running script. This way, the script where Plogger is embedded (default index.php in the Plogger directory) has to be in the same directory as the plog-load_config.php file in order for the mod_rewrite links to be formatted (SCRIPT_FILENAME is the absolute path of index.php and FILE is the absolute path of plog-load_config.php).

I get the same outcome as Kasper with realpath clearing the $_SERVERSCRIPT_NAME? variable since SCRIPT_NAME is absolutely relative to the root (and not a relative path using ./ or ../).

I still think Kasper's workaround is good in case users want to use mod_rewrite in an embedded file not located within the Plogger directly (i.e. www.mysite.com/gallery.php including the scripts from www.mysite.com/plogger/gallery.php) that are not being parsed with their own mod_rewrite paths (i.e. NOT included in Wordpress but in a regular file).

However, I did notice that Kasper's workaround doesn't apply the same $configbaseurl? as the previous code for determining the base url:

$config["baseurl"] = "http://".$_SERVER["HTTP_HOST"]. substr($_SERVER["PHP_SELF"],0,strrpos($_SERVER["PHP_SELF"],"/")) . "/";

So that should be added to the code. And the new commented override code in plog-config.php is missing the closing semi-colon (;). I'll commit these changes tonight when I get home unless someone beats me to it.

Changed 8 months ago by sidtheduck

Should be fixed with r523. Please test in other environments too, but I think this should fix problems people have had.

Changed 7 months ago by sidtheduck

  • status changed from new to closed
  • resolution set to fixed

I'm closing this ticket because I have had multiple success on my server as well as others on the forums with the code in r523 + r526. We can reopen if we run into any other problems.

Changed 7 months ago by sidtheduck

I just noticed on another script I was working on, some server environments that allow users to use PHP4 or PHP5 on their servers (PHP4 is installed by default but some allow the use of PHP5 through a CGI wrapper - examples HostGator? or GoDaddy?) have the SCRIPT_FILENAME path pointing to that of the CGI wrapped PHP installation (i.e. SCRIPT_FILENAME = cgi-bin/php/ instead of the path to the currently running Plogger script). SCRIPT_NAME is still showing correct (although only relative to the document root).

We still may run into some problems with people using Plogger within these server environments and it may warrant another look at how embedding is determined (unless we tell these particular users to override using Kasper's workaround).

Note: See TracTickets for help on using tickets.