0

I want to get ref value from URI which looks like this http://localhost/project/?ref=6 Now I know that $_GET['ref'] will not work in codeigniter. I tried to enable it by setting $config['allow_get_array'] = TRUE; but it didn't work.

I read on SO somewhere about using $this->input->get('ref') but no luck. Before using it I did loaded input library in config.php.

Note: I want to access this value in model

Added in config.php

$config['uri_protocol'] = "PATH_INFO";
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';

and commented existing $config['uri_protocol'] = 'REQUEST_URI'; and $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

Controller code is:

parse_str($_SERVER['QUERY_STRING'], $_GET);
        $ref = $this->security->xss_clean($_GET['ref']);
        log_message('info','>>>>>>>>>>>>>>>>>>enter email_invites method::'.$ref);

But still I don't get any value and somehow I dont see any of my log messages.

Himanshu Yadav
  • 13,315
  • 46
  • 162
  • 291

1 Answers1

2

This line will parse the URL and populate the $_GET array with the URL's parameters:

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

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

$ref = $_GET['ref'];

You config - application/config/config.php - should be set as follows:

$config['uri_protocol'] = "PATH_INFO";
jleft
  • 3,457
  • 1
  • 23
  • 35