GET parameters in URL using CodeIgniter

I know that codeIgniter disables the default GET options.

But if everything is done in POST, isnโ€™t it annoying you to send data again if you ever click back after submitting the form?

This annoys me, but I'm not sure if I want to enable GET solely for this reason.

Is the ability to set GET parameters also such a big security issue?

+48
html post get codeigniter
Dec 02 '08 at 17:05
source share
17 answers

When I first started working with CodeIgniter without using GET, I also dropped it. But then I realized that you can simulate GET parameters by manipulating URIs using the built-in Class URI . This is fantastic and it makes your URLs look better.

Or, if you really need a GET job, you can put this in your controller:

parse_str($_SERVER['QUERY_STRING'], $_GET); 

Which will return the variables to the GET array.

+57
Dec 02 '08 at 17:36
source share

This worked for me:

 <?php $url = parse_url($_SERVER['REQUEST_URI']); parse_str($url['query'], $params); ?> 

$params array contains the parameters passed after? symbol

+13
Oct. 20 2018-10-10
source share

Now it works fine with CodeIgniter 2.1.0

  //By default CodeIgniter enables access to the $_GET array. If for some //reason you would like to disable it, set 'allow_get_array' to FALSE. $config['allow_get_array'] = TRUE; 
+11
Aug 01 2018-12-18T00:
source share

This function is identical to the post function, only it receives data:

 $this->input->get() 

https://www.codeigniter.com/user_guide/libraries/input.html

+10
Jul 05 '13 at 14:27
source share

You just need to include it in config.php, and you can use $this->input->get('param_name'); to get the parameters.

+8
Nov 09 '12 at 7:00
source share

parse_str($_SERVER['QUERY_STRING'],$_GET); ONLY worked for me after I added the following line to application / config / config.php:

$config['uri_protocol'] = "PATH_INFO";

I found $ _GET parameters that are really not needed in CI, but Facebook and other sites reset the GET parameters to the end of the links, which will be 404 for my CI site! By adding a line to config.php, these pages worked. Hope this helps people!

(from http://www.maheshchari.com/work-to-get-method-on-codeigniter/ )

+6
Jun 24 '10 at 18:33
source share

You can include query strings if you really insist. In your config.php you can include the query lines:

 $config['enable_query_strings'] = TRUE; 

For more information, you can see the bottom of this Wiki page: http://codeigniter.com/user_guide/general/urls.html

However, learning to work with clean URLs is the best deal.

+4
Nov 27 2018-11-11T00:
source share

"Don't get annoyed by repeated data requests if you ever click back after submitting a form?

you can get around this by redirecting from a page that handles submitting a form to a success page. the last "action" was loading the success page, not submitting the form, which means that if users run F5, it will simply reload this page and not submit the form again.

+2
Aug 13 '09 at 9:12
source share

If your need for the first parameter uses it.

 $this->uri->segment('3'); 

And your second parameter uses it

 $this->uri->segment('4'); 

You have several options for improving the parameter.

+2
Jun 01 '15 at 9:53 on
source share

allesklar: This is a bit misleading, as scripts and bots can receive POST data almost as easily as sending a normal request. This is not a secret, it is part of HTTP.

+1
Feb 18 '09 at 16:55
source share

A bit of a topic, but I was looking for a get function in CodeIgniter to pass some variables between controllers and meet Flashdata.
see http://codeigniter.com/user_guide/libraries/sessions.html
Flashdata allows you to create quick session data that will be available only for the next server request, and then automatically cleared.

+1
Jan 03 '09 at 3:00
source share

MY_Input.php:

 <?php // this class extension allows for $_GET access class MY_Input extends CI_input { function _sanitize_globals() { // setting allow_get_array to true is the only real modification $this->allow_get_array = TRUE; parent::_sanitize_globals(); } } /* End of file MY_Input.php */ /* Location: .application/libraries/MY_Input.php */ 

MY_URI.php:

 <?php /* | this class extension allows for $_GET access by retaining the | standard functionality of allowing query strings to build the | URI String, but checks if enable_query_strings is TRUE */ class MY_URI extends CI_URI{ function _fetch_uri_string() { if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') { // If the URL has a question mark then it simplest to just // build the URI string from the zero index of the $_GET array. // This avoids having to deal with $_SERVER variables, which // can be unreliable in some environments // // *** THE ONLY MODIFICATION (EXTENSION) TO THIS METHOD IS TO CHECK // IF enable_query_strings IS TRUE IN THE LINE BELOW *** if ($this->config->item('enable_query_strings') === TRUE && is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') { $this->uri_string = key($_GET); return; } // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); if (trim($path, '/') != '' && $path != "/".SELF) { $this->uri_string = $path; return; } // No PATH_INFO?... What about QUERY_STRING? $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); if (trim($path, '/') != '') { $this->uri_string = $path; return; } // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? $path = str_replace($_SERVER['SCRIPT_NAME'], '', (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO')); if (trim($path, '/') != '' && $path != "/".SELF) { // remove path and script information so we have good URI data $this->uri_string = $path; return; } // We've exhausted all our options... $this->uri_string = ''; } else { $uri = strtoupper($this->config->item('uri_protocol')); if ($uri == 'REQUEST_URI') { $this->uri_string = $this->_parse_request_uri(); return; } $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); } // If the URI contains only a slash we'll kill it if ($this->uri_string == '/') { $this->uri_string = ''; } } } /* End of file MY_URI.php */ /* Location: .application/libraries/MY_URI.php */ 
+1
Jul 31 2018-10-18T00:
source share

is my parameter equal? uid = 4 and gets it with:

 $this->uid = $this->input->get('uid', TRUE); echo $this->uid; 

AND

+1
May 23 '16 at 19:03
source share

GET parameters are cached by the web browser, POST is not. So with POST, you donโ€™t have to worry about caching, so this is usually preferable.

0
Dec 02 '08 at 17:08
source share

Even simpler:

 curl -X POST -d "param=value&param2=value" http://example.com/form.cgi 

this plugin is pretty cool though.

0
Aug 9 '09 at 3:46
source share

You can try this

 $this->uri->segment(''); 
0
Sep 30 '14 at 15:47
source share

Do it below. Worked for me. I took values โ€‹โ€‹from the select box and another text box. Then at the click of a button, I took all the data in a Javascript function and redirected using JavaScript.

 //Search Form $(document).ready (function($){ $("#searchbtn").click(function showAlert(e){ e.preventDefault(); var cat = $('#category').val(); var srch = $('#srch').val(); if(srch==""){ alert("Search is empty :("); } else{ var url = baseurl+'categories/search/'+cat+'/'+srch; window.location.href=url; } }); }); 

The above code worked for me.

0
Jun 17 '19 at 7:19
source share



All Articles