Home » HTML » Pager » Bug #6697
Use REQUEST_URI instead of PHP_SELF for href generation
Details
| Submitted | 2006-02-05 15:05 UTC |
|---|---|
| From | plamen at todorov dot biz |
| Assigned | quipo |
| Status | Closed |
| Package | Pager |
| PHP Version | 5.1.0 |
| OS | Windows |
| Roadmaps | (Not assigned) |
Comments
[2006-02-05 15:05 UTC] plamen at todorov dot biz
Description:
------------
I found a bug and here is the description:
If I'm using .htaccess with rewrite engine, Pager doesn't behave as it suppose to. So this is not ussual bug but can be fixed with few replacements, or with adding a new option for factory() method such as 'full_link_url'.
So I found a solutions like this:
in Common.php on line 44:
/*
if (substr($_SERVER['PHP_SELF'], -1) == '/') {
define('CURRENT_FILENAME', '');
define('CURRENT_PATHNAME', str_replace('\\', '/', $_SERVER['PHP_SELF']));
} else {
define('CURRENT_FILENAME', preg_replace('/(.*)\?.*/', '\\1', basename($_SERVER['PHP_SELF'])));
define('CURRENT_PATHNAME', str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])));
}
*/
insted this:
/*
if (substr($_SERVER['REQUEST_URI'], -1) == '/') {
define('CURRENT_FILENAME', '');
define('CURRENT_PATHNAME', str_replace('\\', '/', $_SERVER['REQUEST_URI']));
} else {
define('CURRENT_FILENAME', preg_replace('/(.*)\?.*/', '\\1', basename($_SERVER['REQUEST_URI'])));
define('CURRENT_PATHNAME', str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])));
}
*/
So if we change PHP_SELF to REQUEST_URI everything will be ok because PHP_SELF gets real file, not the file you provided with the rewrite_engine of .htaccess
Test script:
---------------
For .htaccess
Options +Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*\.html$ index.php [L]
In PHP Script:
/* The page where I runing this script is search.html */
function pager($options)
{
require_once("Pager/Pager.php");
$defaults = array(
'mode' => 'Sliding',
'urlVar' => 'page',
'perPage' => 25,
'delta' => 5,
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1,
);
$params = array_merge($defaults, $options);
$pager = & Pager::factory($params);
$links = $pager->getLinks();
return $links['all'];
}
Expected result:
----------------
The link generated href should be ?search.html?PageID=...
Actual result:
--------------
but it is ?index.php?PageID=...