no

How to Allow Url Query String in Codeigniter

As we all know codeigniter uses segment-based as url, example: Just like these: classname/methodname/parameter1/paramenter2, index.php/...

As we all know codeigniter uses segment-based as url, example:

Just like these:

classname/methodname/parameter1/paramenter2,
index.php/index/login/user/password

Unfortunately, I was developing a web application that would accept payments via paypal. And I've use the NVP (Name Value Pair) API. This API returns to your page by calling a query base url which has the authentication token. Of course the codeigniter will pop out a url error message.

Solution:
1.) I've found out that the codeigniter system can be overridden using the hook class.

2.) So first enable hooks in application/config.php
$config['enable_hooks'] = TRUE;

3.) In the hooks documentation codeigniter/general/hooks.html, there are several hook points, we will use the pre_system, because we need to get the $_GET variables before it is read.

4.) In application/config/hooks.php, add the following line:

$hook['pre_system'] = array(
'class' => 'Paypal', //classname
'function' => 'override_get',
'filename' => 'override_get.php',
'filepath' => 'hooks',
'params' => array()
);


5.) Create a file inside, application/hooks named: override_get.php and create the following function:


function override_get() {
if (strlen($_SERVER['QUERY_STRING']) > 0) {
$temp = @array();
parse_str($_SERVER['QUERY_STRING'], $temp);
if (array_key_exists('your_get_variable', $temp)) {
$_POST['your_post_variable'] = $temp['your_get_variable'];
$_SERVER['QUERY_STRING'] = "";
$_SERVER['REDIRECT_QUERY_STRING'] = "";
$_GET = @array();
$url = strpos($_SERVER['REQUEST_URI'], '?');
if ($url > -1) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $url);
}
}
}
}

Related

php 1568622932553360102

Post a Comment Default Comments

item