jeffkee jeffkee - 5 months ago 11
PHP Question

Extplorer $_GET variables being ignored (while echo $_GET['var'] still echoes it..)

I'm using extplorer (http://extplorer.sourceforge.net/) and I'm having some issues.

This runs on PHP.

I did the following so far:
Overrode it so that log in is not required, but rather, checks a $_SESSION var that my own CMS generates upon log-in in order to secure it.
Installed, and confirmed the file/folder dislpays work for the regular root of the site (DOCUMENT_ROOT)

What I'm trying to do now is, each time extplorer is called into an iFrame, I want it to open a different home_dir based on a $_GET var fed through (?idr=35, for example).
However for some odd reason I cannot get this to work.


I tried all sorts of combinations of code to make this work, and when I print_r($GLOBALS) I definitely see the home_dir array holding the path I determine (which should be something like /pages/35/folder as I need to allow my clients to upload small micro-sites to each page folder). I have notated each result with the error I see under FIrebug when the AJAX module calls the files to list the directory etc.

$brixwork_pageid = $_GET['idr'];
$GLOBALS['home_dir'] = $_SERVER['DOCUMENT_ROOT'].'/pages/'.$brixwork_pageid.'/folder';


: did not work. Error:

<br />
<b>Notice</b>: Undefined index: idr in <b>/home/sonikas/public_html/picnetbc/admin/explorer/include/init.php</b> on line <b>76</b><br />
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/sonikas/public_html/picnetbc/admin/explorer/include/result.class.php</b> on line <b>100</b><br />
{'action':'','message':"The home directory doesn\\'t exist, check your settings. (\/home\/sonikas\/public_html\/picnetbc\/pages\/\/folder)",'error':"The home directory doesn\\'t exist, check your settings. (\/home\/sonikas\/public_html\/picnetbc\/pages\/\/folder)",'success':false}


So I tried:

$GLOBALS['home_dir'] = $_SERVER['DOCUMENT_ROOT'].'/pages/'.$_GET['idr'].'/folder';


:also did not work. Error:

<br />
<b>Notice</b>: Undefined index: idr in <b>/home/sonikas/public_html/picnetbc/admin/explorer/include/init.php</b> on line <b>76</b><br />
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/sonikas/public_html/picnetbc/admin/explorer/include/result.class.php</b> on line <b>100</b><br />
{'action':'','message':"The home directory doesn\\'t exist, check your settings. (\/home\/sonikas\/public_html\/picnetbc\/pages\/\/folder)",'error':"The home directory doesn\\'t exist, check your settings. (\/home\/sonikas\/public_html\/picnetbc\/pages\/\/folder)",'success':false}


Then I tried:

$GLOBALS['home_dir'] = $_SERVER['DOCUMENT_ROOT'].'/pages/'.$GLOBALS['__GET']['idr'].'/folder';


:neither did this. Error:

<br />
<b>Notice</b>: Undefined index: idr in <b>/home/sonikas/public_html/picnetbc/admin/explorer/include/init.php</b> on line <b>80</b><br />
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/sonikas/public_html/picnetbc/admin/explorer/include/result.class.php</b> on line <b>100</b><br />
{'action':'','message':"The home directory doesn\\'t exist, check your settings. (\/home\/sonikas\/public_html\/picnetbc\/pages\/\/folder)",'error':"The home directory doesn\\'t exist, check your settings. (\/home\/sonikas\/public_html\/picnetbc\/pages\/\/folder)",'success':false}


So they're basically more or less the same errors. But the weird thing is, if I want to test this module, and I spit out print_r($GLOBALS) I see the home_dir array returning everything including the number that was given, which means that the GET var does get in there somehow. Any help would be appreciated.

Answer

OK So I figured it out - I'm going to write this out so that in case anybody else wants to use this, they can use it.

The issue was that, since this file explorer module (which is fantastic by the way) uses AJAX to make its calls, the initial PHP file opening would get the $_GET var through, but once it makes the AJAX calls, it would send no $_GET vars through!

So instead of tinkering with the javascript to try to pass on the GET vars (which would have taken forever, since I didn't even write this thing and I have no idea where things are), I employed the SESSION var method. Since my CMS uses SESSIONS to log in anyway, the SESSION vars should save. In the init.php file, I put this line instead of the above tinkerings:

if($_REQUEST['explorer_idr']!='') {
    // new request IDR is given - let's save this to a SESSION so that this opens each time on AJAX calls
    $_SESSION['explorer_idr'] = $_REQUEST['explorer_idr'];
}

$GLOBALS['home_dir'] = $_SERVER['DOCUMENT_ROOT'].'/pages/'.$_SESSION['explorer_idr'].'/folder';

To make sure it doesn't clash with anything else, I made the array key "explorer_idr". This way, if a new $_REQUEST['explorer_idr'] is provided, it overrides the $_SESSION['explorer_idr'] to the given value - and if not, it just runs off the previously set var, so that by the time AJAX calls are made (which carry on the SESSION by the way), even if a specific $_GET is not given again, it runs off the saved $_SESSION... and if a $_GET is provided, meaning the user switched to another page, it will simply re-load the $_SESSION var again to make it work!