0

Using Chargify with Codeigniter framework. On completion of signup with Chargify, the return URL can be set with parameters. It seems that these parameters can only be returned ?id=123&ref=321. With Codeigniter, how do I grab those return paramenters?

http://www.website.com/confirmation?id=3163255&ref=5159c58278a1f
SuperNinja
  • 1,538
  • 6
  • 22
  • 45
  • -1 due to lack of efforts. – itachi Apr 01 '13 at 17:45
  • @itachi uh, lack of effort my ass. I've been working on this for the past hour. If I am missing something stupid why not enlighten me instead of voting down with no input. – SuperNinja Apr 01 '13 at 17:47
  • Are you asking how to extract the parameters from the url? If so, then: `$id = $_GET['id'];` and `$ref = $_GET['ref'];` should work. – jleft Apr 01 '13 at 18:19
  • typically that would work. CodeIgniter strips all GET parameters, so without enabling query strings I can't do it this way. Chargify forces this return and I was looking for a solution to handle this. – SuperNinja Apr 01 '13 at 19:46
  • And thanks for actually leaving some constructive feedback Lefters -- @itachi – SuperNinja Apr 01 '13 at 19:50
  • Ah, yes - sorry, I forgot about CodeIgniter destroying the `$_GET` array, really annoying! As you don't want to enable query strings, you could try putting this: `parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);` before trying to access the `$_GET` array like I suggested above. It should populate the array and allow you to access the parameters. No worries, hopefully this might be a bit more helpful! – jleft Apr 01 '13 at 20:27
  • 1
    Dude, exactly what I needed. Can you put into a question so I can hook you up with answer? Thanks @Lefters – SuperNinja Apr 01 '13 at 20:33
  • Cool, glad it worked! Sure, I'll do that now, cheers @Bungdaddy – jleft Apr 01 '13 at 21:01

1 Answers1

2

CodeIgniter, by default, destroys the $_GET variable that one would usually use to access the parameters in a URL.

This line will parse the URL and populate the $_GET array with the URL's parameters. It's useful for when you want to selectively use the $_GET array in a CodeIgniter project, rather than having to enable CodeIgniter's query strings, which would be globally and continually active.

parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);

It can then be accessed as you would normally access an array, for example:

$id  = $_GET['id'];
$ref = $_GET['ref'];
jleft
  • 3,457
  • 1
  • 23
  • 35
  • Please do not duplicate answers. Instead link the question that has the answer already in form of a comment or a duplicate-close-vote. Especially as you duplicate [even your own answers](http://stackoverflow.com/a/15824389/367456). (As you can see duplicate content like these comments are really not helpful for the site in the long run) – hakre Apr 05 '13 at 01:52