IIS $_SERVER['REQUEST_URI']

Proposed developments, distributing tasks, follow-up.

Moderator: jprudhomme

IIS $_SERVER['REQUEST_URI']

Postby ywarnier » Wed Jan 24, 2007 6:06 pm

Since we use it in some places in Dokeos, I thought it was worth mentioning it somewhere. Apparently, IIS doesn't deal correctly with the PHP $_SERVER['REQUEST_URI'] (this probably applies to specific versions of PHP) and that causes, for example, the resourcelinker.php script to remove links to any second-level directory when surfing through the documents to include, in the learning path tool.

Apparently, this page http://neosmart.net/blog/2006/100-apache-compliant-request_uri-for-iis-and-windows/ offers a solution which, even if not really easy to install, will work perfectly. The available request_uri.inc script is apparently enough to get you sorted with a lot of problems, and might be enough for Dokeos.

I don't know, I haven't tested since the IIS+Dokeos server I'm trying to fix is not accessible directly and I have to play with sending files to someone that will apply them.

However, I believe the information might be useful to some people around here.
ywarnier
 
Posts: 971
Joined: Wed Apr 21, 2004 8:48 pm
Location: Lima, Peru

Postby ywarnier » Thu Feb 01, 2007 2:23 am

Yet another side-effect of REQUEST_URI not being handled by IIS can be seen using the studentView (in the top-right corner).
This link should be formed using the following code:
Code: Select all
    if (!strstr($_SERVER['REQUEST_URI'], "?"))
    {
        $sourceurl = $_SERVER['PHP_SELF']."?";
    }
    else
    {
        $sourceurl = $_SERVER['REQUEST_URI'];
    }

...which means that if there is a "?" in the REQUEST_URI, the REQUEST_URI is used (meaning the PHP_SELF + the parameters that went with it), otherwise only the PHP_SELF is used, which normally doesn't involve anything important.

But in IIS case, there *should be* parameters in the REQUEST_URI, but the REQUEST_URI is empty. This means that parameters were there, but will not continue to be there, just because the REQUEST_URI is handled in a bad way. To circumvene this, we can go through the $_GET array and rebuild stuff manually, but it's not very practical.
ywarnier
 
Posts: 971
Joined: Wed Apr 21, 2004 8:48 pm
Location: Lima, Peru

Postby ywarnier » Thu Feb 01, 2007 10:44 am

A possible fix to the previous example would be:
Code: Select all
if (!strstr($_SERVER['REQUEST_URI'], "?"))
    {
        $sourceurl = $_SERVER['PHP_SELF']."?";
        if(is_array($_GET)){
          foreach($_GET as $key=>$value){
            $sourceurl .= $key."=".$value."&";
          }
          $sourceurl = substr($sourceurl,0,-1);
        }
    }
    else
    {
        $sourceurl = $_SERVER['REQUEST_URI'];
    }
ywarnier
 
Posts: 971
Joined: Wed Apr 21, 2004 8:48 pm
Location: Lima, Peru

I have tested IIS6 with the following in main_api.lib.php:

Postby Ivan Tcholakov » Sun Jun 03, 2007 11:00 pm

Code: Select all
// Added by Ivan Tcholakov, 28-JUN-2006.
// Problem to fix: The $_SERVER["REQUEST_URI"] is empty in IIS6.
// Every reference to $_SERVER['REQUEST_URI'] elsewhere in Dokeos should be replaced with calling api_request_uri().
function api_request_uri()
{
   if (!empty($_SERVER['REQUEST_URI']))
   {
      return $_SERVER['REQUEST_URI'];
   }
   else
   {
      $uri = $_SERVER['SCRIPT_NAME'];
      if (!empty($_SERVER['QUERY_STRING']))
      {
         $uri .= '?'.$_SERVER['QUERY_STRING'];
      }
      $_SERVER['REQUEST_URI'] = $uri;
      return $uri;
   }
}


And the system (for production use) was:
Dokeos Community Release 2.0.4
Windows Server 2003 - IIS6.

This fix did not obstruct the running of Dokeos under Apache.

Regards.
Ivan Tcholakov
 
Posts: 197
Joined: Tue Apr 25, 2006 9:14 pm
Location: Bulgaria

This works

Postby Ivan Tcholakov » Thu Dec 04, 2008 6:45 am

I found a confirmation here: http://forums.lifetype.net/viewtopic.php?f=7&t=9161.

Maybe it is time to fix this problem in the repository source? I mean Dokeos 1.8.x (x >= 6).
:)

Regards.

Update: 04-DEC-2008.

I don't like the following suggestion:
Code: Select all
// Every reference to $_SERVER['REQUEST_URI'] elsewhere in Dokeos should be replaced with calling api_request_uri().

It means more work than in this idea in details:

Let us place this function in main_api.lib.php, at the end. Then, in the file global.inc.php let us find the place where the main API file is to be included (currently the lines 45, 46):
Code: Select all
// include the main Dokeos platform library file
require_once($includePath.'/lib/main_api.lib.php');


Let us make this place to be:
Code: Select all
// include the main Dokeos platform library file
require_once($includePath.'/lib/main_api.lib.php');

// Fixing the problem of IIS6 which does not support $_SERVER['REQUEST_URI']
api_request_uri();


Nothing else should be touched. I think, this will work. Right now I have no possibility to test this with IIS6 (+ Windows Server 2003). If somebody tried, any feedback will be useful.

With best regards.

Update, 07-DEC-2008:

Sorry, my mistake. Instead of the correct function name api_request_uri() in the last code line above I had written api_get_request_uri(). This has been corrected. The code is OK now.
Last edited by Ivan Tcholakov on Sun Dec 07, 2008 5:23 am, edited 6 times in total.
Ivan Tcholakov
 
Posts: 197
Joined: Tue Apr 25, 2006 9:14 pm
Location: Bulgaria

Postby ywarnier » Thu Dec 04, 2008 10:24 pm

Feedback of at least 3 people to tell me if it works and I can apply this patch to Dokeos safely would be really appreciated. In fact, the change is ready for 1.8.6, I just have to press "Commit", but I would like to ensure more than one person has tried it...
ywarnier
 
Posts: 971
Joined: Wed Apr 21, 2004 8:48 pm
Location: Lima, Peru

Postby ywarnier » Sun Dec 07, 2008 4:05 am

SVN#17089 adds the function in main_api.lib.php. Waiting for feedback to apply the change to global.inc.php
ywarnier
 
Posts: 971
Joined: Wed Apr 21, 2004 8:48 pm
Location: Lima, Peru

Postby ywarnier » Mon Jan 05, 2009 2:56 pm

Meanwhile no additional feedback has been produced, I have been testing the patch all the way and it didn't break anything, so I'm applying it now (SVN#17534). I have opened http://projects.dokeos.com/index.php?do ... sk_id=3424 and added (shortly) the history of this bug so that we keep a track at development level.
ywarnier
 
Posts: 971
Joined: Wed Apr 21, 2004 8:48 pm
Location: Lima, Peru


Return to Development requests and proposals

Who is online

Users browsing this forum: Google [Bot] and 0 guests