using .htaccess file to disable register globals (register_globals)
The syntax for setting an option is:
php_value name value
php_flag name on or off
Example:
php_flag register_globals off
php_value arg_separator.output &
The example turns off register_globals and sets the value of arg_separator.output to & which is preferred rather than the default &.
Note: you can also set boolean options with the php_value directive, the string will be converted to boolean before assignment.
you can also use .htaccess to turn magic quotes on or off.
Search php.net and you'll find it
기타 질문
다른 분류에 넣을 수 없는 몇몇 질문이 존재합니다. 여기에서 확인할 수 있습니다.
- 윈도우에서 어떻게 bz2 압축 매뉴얼을 다룹니까?
-
bz2 파일을 다루는 압축 도구가 없다면, Redhat에서 명령줄 도구를 » 받을 수 있습니다. (아래에서 추가 정보를 확인하십시오)
명령줄 도구를 사용하기 싫다면, » Stuffit Expander, » UltimateZip, » 7-Zip, » Quick Zip 등의 무료 도구를 사용해 보십시오. » WinRAR이나 » Power Archiver 같은 도구를 가지고 있다면, 그걸로 bz2 파일을 풀 수 있습니다. Total Commander(이전엔 Windows Commandr)를 사용한다면, » Total Commander 사이트에서 bz2 플러그인을 무료로 받을 수 있습니다.
Redhat의 bzip2 명령줄 도구:
Win2k Sp2 사용자는 최신 버전 1.0.2를 받고, 다른 윈도우 사용자는 버전 1.00을 받습니다. 내려받기가 끝난 후 실행 파일을 bzip2.exe로 이름을 바꿉니다. 편하게 사용하기 위해서 path에 있는 디렉토리에 넣습니다. 예. C:\Windows C는 윈도우 설치 드라이브를 나타냅니다.
주의: lang는 언어를 나타내고 x는 형식을 나타냅니다, 예: pdf. php_manual_lang.x.bz2를 풀려면 간단히 다음 절차를 따릅니다:
- 명령 프롬프트 창을 엽니다
- 내려받은 php_manual_lang.x.bz2 파일을 저장한 폴더로 cd 합니다
- bzip2 -d php_manual_lang.x.bz2 를 실행하면, 같은 폴더에 php_manual_lang.x가 풀립니다
많은 html 파일을 포함한 php_manual_lang.tar.bz2를 받았을 경우에도, 절차는 같습니다. 유일한 차이는 php_manual_lang.tar 파일을 얻는 점입니다. tar 형식은 대부분의 윈도우 압축기에서 다룰 수 있습니다. 예. » WinZip.
- 함수 정의에서 인수 옆에 &가 무엇을 의미합니까? 예. asort()
-
이는 인수가 참조로 전달됨을 의미하고, 함수가 문서에 따라 변경할 수 있음을 의미합니다. 변수를 이 방법으로만 전달할 수 있고, 함수 호출에서 &로 전달할 필요가 없습니다. (심지어 배제되었습니다)
- register_globals을 어떻게 다룹니까?
-
register_globals의 보안 문제에 대한 정보를, register_globals 사용하기 보안장에서 읽어보십시오.
register_globals를 켜는 것에 의존하는 대신 자동 전역 사용을 권합니다.
register_globals가 꺼져있는 공유 호스트에서, 켜져있어야 하는 오래된 어플리케이션을 사용해야 할 경우나, 이 기능이 켜져있는 몇몇 호스팅 서버에서 보안 문제를 피하기 위해서 PHP에서 반대 설정을 흉내내야 할 경우가 있습니다. PHP의 설정을 바꾸는 방법으로 해결하는 것이 가장 좋은 방법이겠지만, 불가능할 경우 다음의 호환용 코드 조각을 사용할 수 있습니다.
Example #1 Register Globals 흉내내기
register_globals On을 흉내냅니다. variables_order 지시어를 변경하였다면, $superglobals도 따라서 변경하십시오.
<?php
// register_globals on 흉내내기
if (!ini_get('register_globals')) {
$superglobals = array($_SERVER, $_ENV,
$_FILES, $_COOKIE, $_POST, $_GET);
if (isset($_SESSION)) {
array_unshift($superglobals, $_SESSION);
}
foreach ($superglobals as $superglobal) {
extract($superglobal, EXTR_SKIP);
}
}
?>register_globals Off를 흉내냅니다. 이 코드를 스크립트 처음이나, 세션을 사용한다면 session_start() 이후에 호출해야 하는 점을 명심하십시오.
<?php
// register_globals off 흉내내기
function unregister_GLOBALS()
{
if (!ini_get('register_globals')) {
return;
}
// Might want to change this perhaps to a nicer error
if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
die('GLOBALS overwrite attempt detected');
}
// Variables that shouldn't be unset
$noUnset = array('GLOBALS', '_GET',
'_POST', '_COOKIE',
'_REQUEST', '_SERVER',
'_ENV', '_FILES');
$input = array_merge($_GET, $_POST,
$_COOKIE, $_SERVER,
$_ENV, $_FILES,
isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
foreach ($input as $k => $v) {
if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) {
unset($GLOBALS[$k]);
}
}
}
unregister_GLOBALS();
?>
Considering the comment below. I think there's a way to avoid that "problem":
<?php
//
// $starttime is an example of a variable that we might need to define,
// even before, running the "register_globals OFF" emulator below.
//
list($msec, $sec) = explode(' ', microtime());
$starttime = ((float)$msec + (float)$sec);
//
// If register_globals is ON, ensure no unexpected globals are defined.
// ie. We'll try to emulate a register_globals OFF environment.
//
if( (bool)@ini_get('register_globals') )
{
$superglobals = array($_ENV, $_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
if( isset($_SESSION) )
{
array_unshift($superglobals, $_SESSION);
}
$knownglobals = array(
//
// Known PHP Reserved globals and superglobals:
//
'_ENV', 'HTTP_ENV_VARS',
'_GET', 'HTTP_GET_VARS',
'_POST', 'HTTP_POST_VARS',
'_COOKIE', 'HTTP_COOKIE_VARS',
'_FILES', 'HTTP_FILES_VARS',
'_SERVER', 'HTTP_SERVER_VARS',
'_SESSION', 'HTTP_SESSION_VARS',
'_REQUEST',
//
// Global variables used by this code snippet:
//
'superglobals',
'knownglobals',
'superglobal',
'global',
'void',
//
// Known global variables defined before this code snippet is reached.
//
'starttime',
);
foreach( $superglobals as $superglobal )
{
foreach( $superglobal as $global => $void )
{
if( !in_array($global, $knownglobals) )
{
unset($GLOBALS[$global]);
}
}
}
}
?>
Note the stuff related to the $_SESSION array depends on whether the PHP session has been started or not. You might want to call session_start() before this point (or set session.auto_start ON).
HTH+ :)
If you only needed register_globals for get/post variables, the effictive solution for 5.3 is:
import_request_variables("GPC", "");
But if the skripts relied on session_register() you'll have to do more:
- Replace all variables that appeared after session_register with _SESSION equivalents - so $myvar becomes $_SESSION['myvar']
- Take care if your variables appeared inside strings - 'Hello $user !' works, but 'Hello $_SESSION['user'] !' not - so you have to concatenate the string: 'Hello '.$_SESSION['user'] .' !'
- Session variables in function declarations (for whatever purpose) will not work - keeping the old (local) names will work in most cases.
- Finally, replace the session_register(..) line with session_start()
Regarding simulating register_globals = off, note that it is impossible to adequately prevent $_SESSION variables from being globalised, as the array (and thus the globals) are created on a call to session_start(). You would therefore have to 'undo' this when you start a session as using it at the start of your script will have no effect.
To avoid potential problems, use a prefix that is unique for all session variables (e.g. 'SESS_'), and only access them via the $_SESSION array. The prefix ensures that you don't have a naming clash (and therefore a security risk) with any non-session globals.
