본문 바로가기
PHP

[PHP] session_start(), $_SESSION[]

by 똑똑한 영장류 2012. 12. 13.


수퍼 글로벌 변수 $_SESSION[] 을 사용하는 방법입니다.



$_SESSION[] 변수를 사용하기 전에 다음 함수를 반드시 실행시켜야합니다.


bool session_start ( void )


그래야, 이후,  $_SESSION[] 을 자유롭게 이용할 수 있습니다.


$_SESSION[] 는 배열이니까, 첨자를 이용해서 많은 정보를 다룰 수 있습니다.


$_SESSION['user_id'] = 'member1';


세션에 저장되어 있는 값을 지우고 싶을 때는 아래와 같이 unset() 함수를 이용할 수 있습니다.


unset( $_SESSION['user_id'] );


unset()은 세션 변수뿐아니라 다른 변수에도 모두 사용가능합니다. 노파심에...ㅎㅎ



그리고, 세션에 저장된 정보를 삭제하는 방법은 아래 몇가지 함수들이 있네요.



void session_unset ( void )

The session_unset() function frees all session variables currently registered.




bool session_unregister ( string $name )

session_unregister() unregisters the global variable named name from the current session.




bool session_destroy ( void )

session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again,session_start() has to be called.

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.




'PHP' 카테고리의 다른 글

[PHP] addslashes(), stripslashes() 그리고, get_magic_quotes_gpc()  (1) 2012.12.17
[PHP] isset(), unset()  (1) 2012.12.17
[PHP] mysqli 의 쿼리 결과 다루기  (0) 2012.12.12
[PHP] header()  (0) 2012.12.12
[PHP] md5(), sha1()  (0) 2012.12.11

댓글