Welcome Guest, Not a member yet? Register   Sign In
Problem with equals sign in URI
#1

[eluser]behicthebuilder[/eluser]
Hi guys,

I've been working with CodeIgniter for a few days now and enjoying it (previously CakePHP or custom MVC). Now I've hit my first problem...

I am doing some developement that involves a Payment Gateway making a hit to a page on my site with the transaction outcome details encrypted as a URI parameter - for example:

http://mydomain.com/gateway/callback.php...ample_user

In the above example, the "?result=long_encrypted_string&userid=sample_user" is added by the gateway - and that's the only format it's available in. My problem is that the "really_long_encrypted_string" frequently contains one or more '=' signs in it and this seems to be causing problems in CI.

I have added '=' to the permited characters list:
Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-=';

I have also customized the .htaccess file with a rewrite that formats the callback from the gateway as such:

http://mydomain.com/payments/callback/id...ample_user

Code:
# Rewrite to accomodate question mark and ampersand
# in callback made by Payment Gateway
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^result=(.*)&userid;=(.*)$
RewriteRule ^payments/callback/([0-9]*)/?.*$ index.php?/payments/callback/$1/%1/%2 [L]

Despite this, when there is an '=' in the uri, CI cuts the URI at the location of the '=' sign.

For example, the following rewritten URI:
http://mydomain.com/payments/callback/id...ample_user
turns into:
http://mydomain.com/payments/callback/id...-4Td6s84SD
(notice how anything after the '=' is missing)

This ruins any convenient means of accessing the (full) encrypted string for decryption. I could hack away at $_SERVER['REQUEST_URI'] to extract the relevant info but I'm REALLY hoping someone can suggest anything I'm missing.

Cheers for any help.
#2

[eluser]nevsie[/eluser]
just a quick thought - that possibly won't be helpful at all... but why use a htaccess for this URI at all??
in this case it does not need to be a SEF URL as no user will see it? so why not leave the index.php part in, not rewrite the url and just access them from the $_GET variable???
#3

[eluser]behicthebuilder[/eluser]
Hi nevsie,

Thanks for replying. It's true that this doesn't need to be search engine friendly, the .htaccess rewrite was just in hopes that I could access the uri parameters in the normal CI way:

Code:
$parameter = $this->uri->segment(n); # where n is position/in/uri/

... which works fine with the custom rewrite (with the exception of the segment parsing stopping at an '=' sign, of course).

I had a look at your suggestion regarding using $_GET but I see CI clears this array by default?

For the moment I've settled with rebuilding $_GET based on the request uri just in this controller/method. Still curious as to why the '=' in uri segments causes drama though...

Thanks again.
#4

[eluser]nevsie[/eluser]
i definitely see what your saying about the GET getting destroyed... but then i also see this further down the page:

http://ellislab.com/codeigniter/user-gui...input.html

$this->input->get()
This function is identical to the post function, only it fetches get data:
$this->input->get('some_data', TRUE);

so not sure how what or why happens here!
in the case of the "=" sign... i would either guess a .htacces rewrite error - not my area of expertise but i would guess only the first = is being rewritten, none there after? or perhaps the "=" is being displayed via ascii or another code causing confusion???
#5

[eluser]behicthebuilder[/eluser]
Yeah, I'm pretty stumped.

I've used the same .htaccess code for other framweworks that have similar 'pretty URI' setup without problems. If I get some time I'll dig into the core and try track down where the '=' sign is being cut-off. For now I have got it working by parsing the parameters directly from $_SERVER['REQUEST_URI']. It's only this one page so not really a problem.

Thanks anyway for trying to help out.




Theme © iAndrew 2016 - Forum software by © MyBB