0

I know it's been asked before, but I need it for affiliate tracking...

http://www.mysite.com/controller/method/params?affiliate=123&sub_id=456

How can I get the params AND the $_GET parameters outlined in that URL?

Shamoon
  • 41,293
  • 91
  • 306
  • 570
  • Might want to check out http://codeigniter.com/user_guide/general/urls.html for how CI handles query strings when enabled... – Edd Twilbeck Aug 03 '10 at 15:00
  • also might want to read this - http://stackoverflow.com/questions/2171185/codeigniter-php-framework-need-to-get-query-string – Edd Twilbeck Aug 03 '10 at 15:07

3 Answers3

8

You can always get the data like this:

$this->input->get('your_get_variable', TRUE);

Hope this works!

Dibyendu Mitra Roy
  • 1,604
  • 22
  • 20
3

And yet, sometimes you need access to GET variables in CodeIgniter.

One glaring example is when you use an API that sends a post-back to your site (Paypal, etc.)

The easiest way, in my opinion, is to parse a server variable with the GET data you need since $_GET has been wiped (in my example, REQUEST_URI has my GET data.):

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

This allows the functionality exactly where you need it without requiring a global change to framework settings.

Here is a usage example.

class Pgate extends Controller {
   function postback() {
      parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
      $receipt = $this->input->xss_clean($_GET['receipt']);
   }
}
Community
  • 1
  • 1
Bretticus
  • 896
  • 6
  • 11
0

If you really want to use the query string in codeigniter you can use http://site.com?c=controller&m=method&param1=x&param2=y

This isn't the convention in codeigniter usually people use slashes to delimit params.

Ken Struys
  • 1,789
  • 1
  • 10
  • 17