[eluser]The Questioner[/eluser]
I ran into this same problem when dealing with virtually any payment gateway. It seems as though all payment gateways use GET urls when retuning data back to your ecommerce site. It really annoys me that CI cannot enable both segment URIs and GET querystrings at the same time (for v1.7).
I eventually made some changes in the URI core class to enable simultaneous GET querystring and standard URI segments URLs (for CI v1.7.2). I understand that hacking the core is not ideal, but I didn't have time to wait for this critical feature to be part of a future official release.
I made the following changes in the core URI library
Code:
function _fetch_uri_string()
{
if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
{
// If the URL has a question mark then it's simplest to just
// build the URI string from the zero index of the $_GET array.
// This avoids having to deal with $_SERVER variables, which
// can be unreliable in some environments
if (is_array($_GET) && count($_GET) >= 1 && trim(key($_GET), '/') != '')
{
$this->uri_string=$this->ammend_url_with_get_vars(); //custom function added 24/4/2012
return;
}
// Is there a PATH_INFO variable?
// Note: some servers seem to have trouble with getenv() so we'll test it two ways
$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
if (trim($path, '/') != '' && $path != "/".SELF)
{
$this->uri_string = $path;
return;
}
// No PATH_INFO?... What about QUERY_STRING?
$path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
if (trim($path, '/') != '')
{
$this->uri_string = $path;
return;
}
// No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists?
$path = str_replace($_SERVER['SCRIPT_NAME'], '', (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'));
if (trim($path, '/') != '' && $path != "/".SELF)
{
// remove path and script information so we have good URI data
$this->uri_string = $path;
return;
}
// We've exhausted all our options...
$this->uri_string = '';
}
else
{
$uri = strtoupper($this->config->item('uri_protocol'));
if ($uri == 'REQUEST_URI')
{
$this->uri_string = $this->_parse_request_uri();
return;
}
$this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
}
// If the URI contains only a slash we'll kill it
if ($this->uri_string == '/')
{
$this->uri_string = '';
}
}
I then added some additional functions
Code:
function ammend_url_with_get_vars()
//custom function to force convert any GET variables into standard id/value URIs pairs
//and then remove GET variables from URL path
{
//retrieve current URL (sans base path)
$path=$this->curPageURL(TRUE);
//remove GET values from url
list($path,$querystring) = array_pad(explode('?', $path, 2), 2, null);
//cycle thru each GET variable
foreach ($_GET as $key => $value)
{
//append to end of URL as id/pair URI
$path.='/'.$key.'/'.$value;
};
//return ammened URL path
return $path;
}
function curPageURL($boolRemoveBasePath=FALSE)
//get current page URL
{
$pageURL = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$pageURL .= $_SERVER['SERVER_PORT'] != '80' ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] : $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$pageURL = preg_replace('/:[0-9][0-9][0-9]/', '', $pageURL);
//do we remove the base path?
if ($boolRemoveBasePath)
{
//remove using HTTPS base path and then using HTTP base path
$pageURL = str_replace($this->config->item('base_url_secure'),'', $pageURL);
$pageURL = str_replace($this->config->item('base_url'),'', $pageURL);
};
return $pageURL;
}
Basically this hack collects any GET data, converts them into id/value pairs, and then adds these as additional URI segments to the URL. The querysting section of the URL is then removed.
For example, the mixed URL
Code:
www.yoursite.com/controller/function?datavar1=dataval1&datavar2=dataval2
gets transformed to
Code:
www.yoursite.com/controller/function/datavar1/dataval1/datavar2/dataval2
This allows you to leverage existing CI URI functions to extract the GET values.
I hope this helps some of you fellow coders out.