CodeIgniter를 사용하여 URL에서 매개변수 가져오기
-
22-07-2019 - |
문제
나는 codeIgniter가 기본적으로 GET 매개변수를 끄는 것을 알고 있습니다.
하지만 POST에서 모든 작업을 완료하면 양식 제출 후 다시 버튼을 누르면 데이터 재전송 요청으로 인해 짜증이 나지 않나요?
짜증나지만 이런 이유로 순전히 GET을 허용하고 싶은지 잘 모르겠습니다.
GET 매개변수도 허용하는 것이 그렇게 큰 보안 문제인가요?
해결책
내가 Codeigniter와 처음 일하기 시작했을 때, Get은 실제로 나를 버렸다. 그러나 내장을 사용하여 URI를 조작하여 Get 매개 변수를 시뮬레이션 할 수 있다는 것을 깨달았습니다. URI 클래스. 환상적이며 URL이 더 좋아 보입니다.
또는 실제로 작업이 필요하면 컨트롤러에 넣을 수 있습니다.
parse_str($_SERVER['QUERY_STRING'], $_GET);
변수를 GET 어레이로 다시 넣습니다.
다른 팁
이것은 나를 위해 효과가있었습니다.
<?php
$url = parse_url($_SERVER['REQUEST_URI']);
parse_str($url['query'], $params);
?>
$params
배열에는 이후에 통과 된 매개 변수가 포함되어 있습니까? 캐릭터
이제 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;
이 기능은 게시물 기능과 동일하며 데이터를 가져옵니다.
$this->input->get()
config.php에서 활성화하면 사용할 수 있습니다. $this->input->get('param_name');
매개 변수를 얻으려면.
parse_str($_SERVER['QUERY_STRING'],$_GET);
apps/config/config.php에 다음 줄을 추가한 후에만 효과가 있었습니다:
$config['uri_protocol'] = "PATH_INFO";
CI에서는 $_GET 매개변수가 실제로 필요하지 않다는 것을 알았지만 Facebook과 다른 사이트에서는 내 CI 사이트에 대해 404가 될 링크 끝에 GET 매개변수를 덤프합니다!!config.php에 위의 줄을 추가하면 해당 페이지가 작동했습니다.이것이 사람들에게 도움이 되기를 바랍니다!
(에서 http://www.maheshchari.com/work-to-get-method-on-codeigniter/)
실제로 주장하면 쿼리 문자열을 활성화 할 수 있습니다. config.php에서 쿼리 문자열을 활성화 할 수 있습니다.
$config['enable_query_strings'] = TRUE;
자세한 정보는이 위키 페이지의 하단을보십시오.http://codeigniter.com/user_guide/general/urls.html
그럼에도 불구하고 깨끗한 URL과 함께 일하는 법을 배우는 것이 더 나은 제안입니다.
"양식 제출 후 다시 누르면 다시 삭감 데이터 요청에 짜증이 나지 않습니다."
양식 제출을 성공 페이지로 처리하는 페이지에서 리디렉션을 수행 하여이 문제를 해결할 수 있습니다. 마지막 "액션"은 양식 제출이 아닌 성공 페이지의로드였습니다. 즉, 사용자가 F5를 수행하면 해당 페이지를 다시로드하고 양식을 다시 제출하지 않습니다.
먼저 매개 변수가 필요하다면 사용하십시오.
$this->uri->segment('3');
그리고 두 번째 매개 변수가 필요합니다
$this->uri->segment('4');
많은 매개 변수 향상 매개 변수가 있어야합니다
Allesklar : 스크립트와 봇이 정상적인 요청을 보내는 것만 큼 쉽게 데이터를 게시 할 수 있기 때문에 약간 오해의 소지가 있습니다. 비밀이 아니며 HTTP의 일부입니다.
주제가 조금 떨어졌지만 CodeIgniter에서 GET 함수를 찾고 있었으며 컨트롤러간에 일부 변수를 전달하고 FlashData를 가로 질러 나옵니다.
보다 : http://codeigniter.com/user_guide/libraries/sessions.html
FlashData를 사용하면 다음 서버 요청에만 사용할 수있는 빠른 세션 데이터를 만들 수 있으며 자동으로 지우겠습니다.
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's 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 */
내 매개 변수는? uid = 4이고 다음과 같이 얻습니다.
$this->uid = $this->input->get('uid', TRUE);
echo $this->uid;
wis
Get 매개 변수는 웹 브라우저에 의해 캐시되며 게시물은 그렇지 않습니다. 따라서 게시물을 사용하면 캐싱에 대해 걱정할 필요가 없으므로 일반적으로 선호됩니다.
당신은 이것을 시도 할 수 있습니다
$this->uri->segment('');
더 쉽게 :
curl -X POST -d "param=value¶m2=value" http://example.com/form.cgi
그 플러그인은 꽤 멋지다.
아래에서 이것을하십시오. 나를 위해 일했습니다. 선택 상자와 다른 텍스트 상자에서 값을 가져 왔습니다. 그런 다음 버튼 클릭으로 전체 데이터를 JavaScript 함수로 가져 와서 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;
}
});
});
위의 코드는 저에게 효과적이었습니다.