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

[eluser]drewbee[/eluser]
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.


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

[eluser]xwero[/eluser]
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

[eluser]Yorkshire Pudding[/eluser]
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)

Code:
http://localhost/mysite/index.php/home/order_success?crypt=DycAHF1HGiA1WRU9VFFGA2tkOChhYTYREgsKGyogQAQbdFpVAgd8HFsEMGlRSUBxbnRDOgIMDWswd0lpWlJJSH8RGhlGQD1lOX1XCx0FBUAqBgsMU1wiZUYGQWhJXlFhMSdOOUdBJjcEXwI5HQ0eW3k1DwsSZjs7FVMCKw8RHRt/FhY5R0EmFhkLRWlQU0kDb2QvLmF2GGpLcjAMKEQ/eg1iLTB3dgUdMhAwPA0WFEYqEAsLR1k6ZTh5JQg7Kyd8HQcqXmJaPSw1WRU9OwECQDU2UzZ9YR4KOWA4HCwgV3YPcDwdQUAiLEt4Pgw5Nj5jEAYrPBRyJz4Cdxg8VFRXBh0RCxtHRysLAlcFLRpZP3oNASY9cX4LHFB3HDccCgUIaHdASAI=

to:

Code:
http://localhost/mysite/index.php/home/order_success
then we can use $hook['pre_system'] to define a constant with $_SERVER['QUERY_STRING'] as xwero suggested earlier?
#24

[eluser]Yorkshire Pudding[/eluser]
yep it's set to 'auto' but you've lost me on that one
#25

[eluser]xwero[/eluser]
use path_info that should do the trick.
#26

[eluser]drewbee[/eluser]
Wait, so this isn't working?

Pre system hook:

Code:
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

[eluser]Yorkshire Pudding[/eluser]
Thanks guys. I haven't got it too work yet but i think

using a pre system hook

Code:
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

[eluser]xwero[/eluser]
I had no problem with the solution i proposed that had this code
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

[eluser]Yorkshire Pudding[/eluser]
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

[eluser]xwero[/eluser]
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
Code:
parse_str($_SERVER['QUERY_STRING'],$_GET);




Theme © iAndrew 2016 - Forum software by © MyBB