* 암호화

if(!function_exists('password_hash')) {
	$this->load->helper('password');
}

$hash = password_hash($this->input->post('password'),PASSWORD_BCRYPT); // 암호화된 비밀번호

password.php
다운로드

* 로그인 검증

if($this->input->post('email') && password_verify($this->input->post('password'),$user->password)) {
	// 성공
} else {
	// 실패
}

'php, codeigniter' 카테고리의 다른 글

메일 전송하기  (0) 2014.10.15
url 헬퍼 - site_url / redirect  (0) 2014.10.15
세션(session) 이용하기  (0) 2014.10.15
로그파일 설정 및 처리  (0) 2014.10.14
config[] 환경 설정하기  (0) 2014.10.14
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,

* /application/autoload.php

$autoload['libraries'] = array(); // 부분에 session을 설정하는게 편함

* /application/config.php

$config['encryption_key'] = ''; // 이 부분에 암호화 룰을 설정한다
$config['sess_use_database'] = FALSE; // TRUE 권장, 디비로 세션 정보 저장
$config['sess_table_name'] = 'ci_sessions'; // 테이블 이름
$config['sess_match_ip'] = FALSE; // TRUE 권장, IP 매칭

* 테이블 스키마

CREATE TABLE IF NOT EXISTS `ci_sessions` (
	session_id varchar(40) DEFAULT '0' NOT NULL,
	ip_address varchar(16) DEFAULT '0' NOT NULL,
	user_agent varchar(120) NOT NULL,
	last_activity int(10) unsigned DEFAULT 0 NOT NULL,
	user_data text NOT NULL,
	PRIMARY KEY (session_id),
	KEY `last_activity_idx` (`last_activity`)
);

* 컨트롤러

- 저장 : $this->session->set_userdata('session_test','value');
- 삭제 : $this->session->unset_userdata('session_test');
- 확인 : echo $this->session->userdata('session_test');

* flashdata - 단 한버만 사용되고 삭제되는 세션

저장 : $this->session->set_flashdata('message','로그인 실패');
확인 : echo $this->session->flashdata('message');

'php, codeigniter' 카테고리의 다른 글

url 헬퍼 - site_url / redirect  (0) 2014.10.15
사용자 비밀번호 암호화(password_bcrypt)  (0) 2014.10.15
로그파일 설정 및 처리  (0) 2014.10.14
config[] 환경 설정하기  (0) 2014.10.14
get_magic_quotes_gpc()  (0) 2014.10.14
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,

* /application/config/config.php

$config['log_threshold'] = 0;

* MVC(Model, View, Controller)

log_message('debug','게시판 로딩중'); // 흐름
log_message('var',var_export($board_id,1)); // 변수값 출력
show_error('에러 메시지') // '에러 메시지'가 출력되면서 멈춤

'php, codeigniter' 카테고리의 다른 글

사용자 비밀번호 암호화(password_bcrypt)  (0) 2014.10.15
세션(session) 이용하기  (0) 2014.10.15
config[] 환경 설정하기  (0) 2014.10.14
get_magic_quotes_gpc()  (0) 2014.10.14
form validation(폼 유효성 검사)  (0) 2014.10.13
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,
$this->load->config('test') // config 폴더안에 test.php 환경파일 로드

* test.php

config['test'] = true;

* MVC 로드 방법

echo $this->conifg->item('test');

'php, codeigniter' 카테고리의 다른 글

세션(session) 이용하기  (0) 2014.10.15
로그파일 설정 및 처리  (0) 2014.10.14
get_magic_quotes_gpc()  (0) 2014.10.14
form validation(폼 유효성 검사)  (0) 2014.10.13
헬퍼(helper) 만들어서 사용하기  (0) 2014.10.13
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,
if(get_magic_quotes_gpc()) {
	$contents = $_POST['contents'];
} else {
	$contents = addslashes($_POST['contents']);
}
 

'php, codeigniter' 카테고리의 다른 글

로그파일 설정 및 처리  (0) 2014.10.14
config[] 환경 설정하기  (0) 2014.10.14
form validation(폼 유효성 검사)  (0) 2014.10.13
헬퍼(helper) 만들어서 사용하기  (0) 2014.10.13
$_POST 값이 안넘어올때  (0) 2014.10.13
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,

* 컨트롤러

$this->load->library('form_validation');
$this->form_validation->set_rules('title', '제목', 'required'); // 필드 검사
$this->form_validation->set_rules('description', '본문', 'required'); // 필드 검사

 

- required : 필수

- min_length[5] : 최소 5자

- max_length[10] : 최대 10자

- matches[re_password] : password 필드와 매칭

- valid_email : 메일주소 유효성

- is_unique[user.email] : user 테이블의 email 필드중에 중복값 검색

if ($this->form_validation->run() == FALSE) {
	$this->load->view('add');
} else {
	$topic_id = $this->topic_model->add($this->input->post('title'), $this->input->post('description'));
}

* 뷰

<?php echo validation_errors(); ?>
출처 : http://opentutorials.org/course/697/3835

 

'php, codeigniter' 카테고리의 다른 글

config[] 환경 설정하기  (0) 2014.10.14
get_magic_quotes_gpc()  (0) 2014.10.14
헬퍼(helper) 만들어서 사용하기  (0) 2014.10.13
$_POST 값이 안넘어올때  (0) 2014.10.13
지정된 날짜에만 팝업창 열기  (0) 2014.10.12
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,