Welcome Guest, Not a member yet? Register   Sign In
specific controllers allowing query strings

[eluser]Yorkshire Pudding[/eluser]
Hi, does anybody know a way of allowing query strings to be used in specific controller? Is there a way of using wildcards / reg expression explained in docs(URI routing) to be able to grab the variable and route it through to my controller without having to enable query strings across the board?

basically our payment gateway sends our customers back to a success or failure page and attaches a get value with details of the transaction.

e.g. http:/mysite/index.php/home/order_success?crypt=DycAHF1HGiA1WRU9

I know i could set up a subfolder outside of CI but i wouldn't have the use of all my models which just means i'd have to write it all out again in vanilla PHP.


I can't remember if the stock htaccess can tell the difference between actual files, and files that do not exist but get routed through the CI controller.

Currently any file that does literally exist does not get processing through CI for me. I had this situation come up with paypal and did something to the tea of:

header("Location: /paypal/process_transaction/" . $_GET['crypt']);

That is a down and dirty sample of what I did, as I didn't do any data cleansing, but I hope you get the idea.

Also if anyone else has a better way, let me know. Two http requests are going to happen for each transaction this way.

you would simply post the transaction to example.com/paypal.php?crypt=df908as7dfd


I actually created a directory at the root called 'bootstraps' and this is where I place these type of situation files.

[eluser]Yorkshire Pudding[/eluser]
Thanks for the reply.

This seems like a good solution to the problem for now. Will implement that and see if I can come up with another way of getting round it.

A hackish solution is to define a MY_GET constant in the constants.php file the fetches the GET values
Then is doesn't matter what your settings are.

[eluser]Yorkshire Pudding[/eluser]
Hi, thanks for reply. I get this message using this method.

Warning: Constants may only evaluate to scalar values in C:\wamp\www\mysite.co.uk\system\application\config\constants.php on line 4

I don't know the inner workings of CI, so don't really understand this solution.

Quote:Warning: Constants may only evaluate to scalar values

Have a look at http://php.net/define:
Quote:The value of the constant; only scalar and null values are allowed. Scalar values are integer, float, string or boolean values.

In order to use an array constant you'd have to serialize it.

It's a php error. You can't add an array as a value of a constant. So you have to work with
To get the key value(s) out from the string you can use this function
function get_pairs($key='')
   // all pairs
      return $pairs;
   // some pairs
      $keys = array_keys($pairs);
      $output = array();
      foreach($key as $k)
            $output[$k] = $pairs[$k];
      return $output
   // a pair value
      return $pairs[$key];
Another solution based on the same constant is to repopulate the GET global with the constant after the input class cleaned the globals. The pre_controller hook is best suited for this.

[eluser]Yorkshire Pudding[/eluser]
Thanks for these solutions. I'll have to dust off the old php book and read up on this. I'm just a framework monkey really :cheese: but i'll have a bash at this last solution.

[quote author="pistolPete" date="1236701916"]In order to use an array constant you'd have to serialize it.[/quote]
serializing is another solution but i don't think it matters much if you do
$pairs = unserialize(MY_GET);
in the function i wrote before.

[eluser]Yorkshire Pudding[/eluser]
I'm going to use the first solution given(so i can get the site up), until I have time to understand and implement the second solution.

the crypt that protx sends back is


which poses a few problems. Firstly it has '/' in it so it looks like additional url segment, and secondly it has '=' in it which is a disallowed character in config file.

Two questions really then.

1. Is it secure to allow '=' in the permitted_uri_chars.
2. Any ideas on how to overcome the '/' problem (urlencode() perhaps?)

Theme © iAndrew 2016 - Forum software by © MyBB