That is something i didn’t think of so you would have to create a route like this one
$route['(home)/(order_success)(.+)'] = '$1/$2';This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
March 09, 2009 2:11pm
Subscribe [3]#16 / Mar 10, 2009 1:56pm
That is something i didn’t think of so you would have to create a route like this one
$route['(home)/(order_success)(.+)'] = '$1/$2';#17 / Mar 10, 2009 2:32pm
still getting a 404 using a route
tried
$route['home/(^order_success)'] = "home/order_success";
$route['home/^order_success'] = "home/order_success";
$route['home/order_success'] = "home/order_success";the url i want to redirect is:
<a href="http://localhost/mysite/index.php/home/order_success?crypt=DycAHF1HGiA1WRU9VFFGA2tkOChhYTYREgsKGyogQAQbdFpVAgd8HFsEMGlRSUBxbnRDOgIMDWswd0lpWlJJSH8RGhlGQD1lOX1XCx0FBUAqBgsMU1wiZUYGQWhJXlFhMSdOOUdBJjcEXwI5HQ0eW3k1DwsSZjs7FVMCKw8RHRt/FhY5R0EmFhkLRWlQU0kDb2QvLmF2GGpLcjAMKEQ/eg1iLTB3dgUdMhAwPA0WFEYqEAsLR1k6ZTh5JQg7Kyd8HQcqXmJaPSw1WRU9OwECQDU2UzZ9YR4KOWA4HCwgV3YPcDwdQUAiLEt4Pgw5Nj5jEAYrPBRyJz4Cdxg8VFRXBh0RCxtHRysLAlcFLRpZP3oNASY9cX4LHFB3HDccCgUIaHdASAI=">http://localhost/mysite/index.php/home/order_success?crypt=DycAHF1HGiA1WRU9VFFGA2tkOChhYTYREgsKGyogQAQbdFpVAgd8HFsEMGlRSUBxbnRDOgIMDWswd0lpWlJJSH8RGhlGQD1lOX1XCx0FBUAqBgsMU1wiZUYGQWhJXlFhMSdOOUdBJjcEXwI5HQ0eW3k1DwsSZjs7FVMCKw8RHRt/FhY5R0EmFhkLRWlQU0kDb2QvLmF2GGpLcjAMKEQ/eg1iLTB3dgUdMhAwPA0WFEYqEAsLR1k6ZTh5JQg7Kyd8HQcqXmJaPSw1WRU9OwECQDU2UzZ9YR4KOWA4HCwgV3YPcDwdQUAiLEt4Pgw5Nj5jEAYrPBRyJz4Cdxg8VFRXBh0RCxtHRysLAlcFLRpZP3oNASY9cX4LHFB3HDccCgUIaHdASAI=</a>thanks
#18 / Mar 10, 2009 2:41pm
Im not quite sure how you would deal with the question mark though…
$route['home/order_success(.*)] = 'home/order_success/' . str_replace('?crypt=', '', $1);Edit: That is probobly all kinds of wrong. :D
#19 / Mar 10, 2009 2:48pm
If i use $hook[‘pre_system’] instead of $hook[‘pre_controller’] i shouldn’t need to deal with the query string? I just want to strip it out and redirect them to ‘home/order_success’.
I should then be able to call the constant from within my controller?
#20 / Mar 10, 2009 2:49pm
tried $route[‘home/order_success(.*)’] = “home/order_success” and still got a CI 404 btw
#21 / Mar 10, 2009 3:12pm
What if we do a redirect from the pre_system hook? We really don’t have any of CI initialized so we will be doing straight out php code.
if ($_SERVER['SCRIPT_FILENAME'] == '/mysite/index.php/home/order_success/index.php' && isset($_GET['crypt']))
{
header("Location: /mysite/index.php/home/order_success/" . $_GET['crypt']);
unset($_GET['crypt']); // if for some reason the redirect doesn't work.
}Please note this will work on any page, so you *should* do some extra work to make sure it only registers on the home/order_success controller using $_SERVER[‘SCRIPT_FILENAME’].
#22 / Mar 10, 2009 3:29pm
are you using the uri_protocol auto setting? if you do this is the problem as it fetched a single as a controller no matter the key is. change it and then you don’t need routes if i’m right.
#23 / Mar 10, 2009 3:29pm
nice idea, but the crypt that the payment gateway sends back includes ‘/’ and ‘=’ etc. I tried a similar thing earlier using a file outside of CI to redirect. I used urlencode() / urldecode() and then the header() function but couldn’t get it to work. I’m pretty sure that if someone can figure how to route this url. (Essentially just stripping away everything after and including the question mark)
<a href="http://localhost/mysite/index.php/home/order_success?crypt=DycAHF1HGiA1WRU9VFFGA2tkOChhYTYREgsKGyogQAQbdFpVAgd8HFsEMGlRSUBxbnRDOgIMDWswd0lpWlJJSH8RGhlGQD1lOX1XCx0FBUAqBgsMU1wiZUYGQWhJXlFhMSdOOUdBJjcEXwI5HQ0eW3k1DwsSZjs7FVMCKw8RHRt/FhY5R0EmFhkLRWlQU0kDb2QvLmF2GGpLcjAMKEQ/eg1iLTB3dgUdMhAwPA0WFEYqEAsLR1k6ZTh5JQg7Kyd8HQcqXmJaPSw1WRU9OwECQDU2UzZ9YR4KOWA4HCwgV3YPcDwdQUAiLEt4Pgw5Nj5jEAYrPBRyJz4Cdxg8VFRXBh0RCxtHRysLAlcFLRpZP3oNASY9cX4LHFB3HDccCgUIaHdASAI=">http://localhost/mysite/index.php/home/order_success?crypt=DycAHF1HGiA1WRU9VFFGA2tkOChhYTYREgsKGyogQAQbdFpVAgd8HFsEMGlRSUBxbnRDOgIMDWswd0lpWlJJSH8RGhlGQD1lOX1XCx0FBUAqBgsMU1wiZUYGQWhJXlFhMSdOOUdBJjcEXwI5HQ0eW3k1DwsSZjs7FVMCKw8RHRt/FhY5R0EmFhkLRWlQU0kDb2QvLmF2GGpLcjAMKEQ/eg1iLTB3dgUdMhAwPA0WFEYqEAsLR1k6ZTh5JQg7Kyd8HQcqXmJaPSw1WRU9OwECQDU2UzZ9YR4KOWA4HCwgV3YPcDwdQUAiLEt4Pgw5Nj5jEAYrPBRyJz4Cdxg8VFRXBh0RCxtHRysLAlcFLRpZP3oNASY9cX4LHFB3HDccCgUIaHdASAI=</a>to:
<a href="http://localhost/mysite/index.php/home/order_success">http://localhost/mysite/index.php/home/order_success</a>then we can use $hook[‘pre_system’] to define a constant with $_SERVER[‘QUERY_STRING’] as xwero suggested earlier?
#24 / Mar 10, 2009 3:33pm
yep it’s set to ‘auto’ but you’ve lost me on that one
#25 / Mar 10, 2009 3:34pm
use path_info that should do the trick.
#26 / Mar 10, 2009 3:37pm
Wait, so this isn’t working?
Pre system hook:
if (isset($_GET['crypt']))
{
define('CRYPT', $_GET['crypt']);
unset($_GET['crypt');
}then visiting /home/order_success?crypt=asdfasdfasdfasdf
It should unset the $_GET used to prevent it from crashing in CI as invalid characters, and all will be will (or should be) in the controller.
This is under the hopefull thought that permitted uri chars hasn’t been checked yet.
My thinking sais this should create the constant anytime the query_string var crypt is set. No need for routes or htaccess.
#27 / Mar 10, 2009 3:52pm
Thanks guys. I haven’t got it too work yet but i think
using a pre system hook
if (isset($_GET['crypt']))
{
define('CRYPT', $_GET['crypt']);
unset($_GET['crypt');
}will work a treat.
I’ll try in the morning and update. I’ve got to leave work now as they’ll lock the gate :-( I’ll update this post in the morning.
#28 / Mar 11, 2009 4:45am
I had no problem with the solution i proposed that had this code
// constants.php
define('GET_HACK',$_SERVER['QUERY_STRING']);
// config.php
$config['uri_protocol'] = "PATH_INFO";
$config['enable_hooks'] = TRUE;
$config['enable_query_strings'] = false;
// hooks.php
$hook['pre_controller'] = array(
'function' => 'const_to_get',
'filename' => 'get_hack.php',
'filepath' => 'hooks',
);
// get_hack.php
<?php
function const_to_get()
{
parse_str(GET_HACK,$_GET);
}I even tried your query string.
#29 / Mar 11, 2009 6:59am
Thanks, both methods worked fine. Ended up using xwero’s method as I don’t need to write a separate rule if i need to grab different get values.
So in summary…
1. implement everything as in the above post.
2. use $_GET[‘crypt’] in controller to grab value
Cheers for everyone’s help
#30 / Mar 12, 2009 6:00am
I was making it too difficult. the SERVER global isn’t cleaned and there the GET global is stored as QUERY_STRING. So if you set the uri_protocol to PATH_INFO you can localize the GET global to the controller method if you want using
parse_str($_SERVER['QUERY_STRING'],$_GET);