회원 로그인
|
CodeIgniter(코드이그나이트) 사용
CodeIgniter(코드이그나이트) 사용
설치
- https://codeigniter.com에서 다운로드 (2015.12.6 기준 v3.0.3)
- 압축을 풀고 웹서버의 home 디렉토리에 원하는 폴더로 바꾸어 업로드
- mysql 설정
사용
- config/database.php - db 설정
database.php
- application/controllers - POST, GET등 으로 받은 정보를 models의 클래스를 요청하여 인/아웃풋 처리
game.php
- application/models - 기본적인 사용 클래스 정의(join.php, login.php 등 중복이 되는 부분 클래스화)
user.php
접근
- http://주소/설치루트디렉토리/index.php/controllers php명/클래스명
예) http://주소/home/index.php/game/login
3.0 한글 매뉴얼> http://www.ciboard.co.kr/user_guide/kr
설치
- https://codeigniter.com에서 다운로드 (2015.12.6 기준 v3.0.3)
- 압축을 풀고 웹서버의 home 디렉토리에 원하는 폴더로 바꾸어 업로드
- mysql 설정
사용
- config/database.php - db 설정
database.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); /* 주석 생략 */ //$active_group = 'default'; $active_group = 'game_db'; $query_builder = TRUE; // $db['default'] = array( $db['game_db'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => '사용자명', 'password' => 'DB패스워드', 'database' => 'DB명', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => FALSE, //(ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );
- application/controllers - POST, GET등 으로 받은 정보를 models의 클래스를 요청하여 인/아웃풋 처리
game.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Game extends CI_Controller { /** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/<method_name> * @see http://codeigniter.com/user_guide/general/urls.html */ // modles의 user.php 참조하여 결과 출력 function __construct() { parent::__construct(); // 유저 모델 객체 참조 $this->load->model("User", "user_model"); } public function index() { echo "Game Controller!!"; } public function login(){ // $user_id = $_POST["user_id"] // php 문법 // post 데이터 추출 // 코드이그나이트 (보안처리 가능) // $user_id = $this->input->post("user_id"); // $user_pw = $this->input->post("user_pw"); // post 데이터 추출 $user_info = array(); $user_info["user_id"] = $this->input->post("user_id"); $user_info["user_pw"] = $this->input->post("user_pw"); // 응답 딕셔너리 객체 생성 $res_data = array( "RESULT" => "EMPTY_ACCOUNT" ); // 아이디와 비번 중에 빈값이 있다면 회원 가입 실패 if (!($user_info["user_id"] && $user_info["user_pw"])){ echo json_encode($res_data); exit(); } // 유저 모델 객체에게 로그인을 요청함 $result = $this->user_model->login($user_info); // 로그인 정보가 있다면 if ($result != null){ $res_data["RESULT"] = "LOGIN_SUCCESS"; $res_data["INFO"] = $result; echo json_encode($res_data); } else { // 로그인 정보가 없다면 $res_data["RESULT"] = "LOGIN_FAIL"; echo json_encode($res_data); } } public function join(){ echo "게임 가입"; // 모델 객체의 id 체크 메소드 호출 // 모델 객체의 회원 가입 메소드 호출 } // 스코어 업데이트 public function score_update() { $user_info = array(); $user_info["user_id"] = $this->input->post("user_id"); $user_info["best_score"] = $this->input->post("best_score"); // 응답 딕셔너리 객체 생성 $res_data = array( "RESULT" => "EMPTY_ACCOUNT" ); // 유저 모델 객체에게 로그인을 요청함 $result = $this->user_model->score_update($user_info); if ($result) { $res_data["RESULT"] = "SCORE_UPDATE_SUCCESS"; } else { $res_data["RESULT"] = "SCORE_UPDATE_FAIL"; } echo json_encode($res_data); } }
- application/models - 기본적인 사용 클래스 정의(join.php, login.php 등 중복이 되는 부분 클래스화)
user.php
<?php // 유저 모델 클래스 // models에서 db접근 관련 script 작성 defined('BASEPATH') OR exit('No direct script access allowed'); // CI_Model 상속 해야함 class User extends CI_Model { // 게임 데이터베이스 객체 참조 변수 var $game_db; // 생성자 function __construct() { parent::__construct(); // CI_Model의 생성자 호출 // 데이터베이스 연결 $this->game_db = $this->load->database("DB명", true); } // 게임 유저 로그인 // $user_info controllers에서 넘어옴 function login($user_info) { // game.php 컨트롤러에서 넘어온 파라미터값 추출 $user_id = $user_info["user_id"]; $user_pw = $user_info["user_pw"]; // 코드이그나이트로 'sql 인젝션'' 보안 해결 // (바인딩) 쿼리 작성 $sql = "SELECT * FROM game_tb WHERE id=? && pw=?;"; // 쿼리 바인딩 $bind_param = array( $user_id, $user_pw ); // 쿼리 실행 $query_result = $this->game_db->query($sql, $bind_param); // 조회한 레코드의 갯수가 0 이상이면 if ($query_result->num_rows() > 0){ // num_rows() - count 갯수 추출 // 조회 결과 배열에서 행단위로 추출함 // 테이블 => $result->result() // 행 => $row foreach ($query_result->result() as $row){ // C# foreach($row in $query_result->result()) {} return $row; } } return null; } // 스코어 업데이트 function score_update($user_info){ $user_id = $user_info["user_id"]; $best_score = $user_info["best_score"]; $sql = "UPDATE game_tb SET best_score=? WHERE id=?;"; $bind_param = array( $best_score, $user_id ); // 게임 정보 수정 쿼리 실행 $query_result = $this->game_db->query($sql, $bind_param); // 쿼리 실행 결과 갯수가 1개라도 있으면 수정 성공 if ($this->game_db->affected_rows() > 0) { return true; } else { return false; } } // 가입 function join() { } // id체크(중복 등) function idcheck() { } // 수정 function update() { } } ?>
접근
- http://주소/설치루트디렉토리/index.php/controllers php명/클래스명
예) http://주소/home/index.php/game/login
3.0 한글 매뉴얼> http://www.ciboard.co.kr/user_guide/kr
댓글 0개
| 엮인글 0개
285개(1/15페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
285 | [Python] 동적 import - 모듈을 변수로 받아오기 | 푸딩뱃살 | 405 | 2022.10.27 10:45 |
284 | [Python] 파이썬 3.7.7과 3.9.7의 os.path.expanduser() 차이 | 푸딩뱃살 | 440 | 2022.08.18 12:22 |
283 | [Python] error: Microsoft Visual C++ 9.0 is required. | 푸딩뱃살 | 659 | 2022.08.03 13:35 |
282 | [Python] pyscript | 푸딩뱃살 | 434 | 2022.06.09 11:21 |
281 | [Python] float is / float not is | 푸딩뱃살 | 583 | 2022.03.02 15:03 |
280 | [Python] 이터널 문자열 f | 푸딩뱃살 | 811 | 2022.01.27 16:35 |
279 | [Python] is와 ==의 차이 | 푸딩뱃살 | 475 | 2021.11.25 15:54 |
278 |
[Python] Error: ImportError: file |
푸딩뱃살 | 892 | 2021.11.16 11:24 |
277 | [Python] 파이썬 디컴파일 - uncompyle6 | 푸딩뱃살 | 752 | 2021.11.10 14:46 |
276 | [Python] 파이썬 확장자 설명 | 푸딩뱃살 | 539 | 2021.11.03 14:38 |
275 | [참고] 웹 fbx 뷰어 | 푸딩뱃살 | 457 | 2021.10.19 15:46 |
274 | [Python] enumerate() | 푸딩뱃살 | 487 | 2021.10.13 14:44 |
273 | [Python] 아나콘다에서 가상 환경 | 푸딩뱃살 | 696 | 2020.11.21 00:26 |
272 | [Python] pip로 설치 때 퍼미션 에러 | 푸딩뱃살 | 1249 | 2020.06.06 17:13 |
271 | [Python] OpenCV 10-3. 이미지 Thresholding - Otsu's Binarizatio | 푸딩뱃살 | 659 | 2020.06.05 14:01 |
270 | [Python] OpenCV 10-2. 이미지 Thresholding - Adaptive Threshold | 푸딩뱃살 | 679 | 2020.06.05 13:58 |
269 | [Python] OpenCV 10-1. 이미지 Thresholding | 푸딩뱃살 | 569 | 2020.06.05 13:56 |
268 | [Python] OpenCV 9-2. 색 추적 | 푸딩뱃살 | 745 | 2020.06.02 23:29 |
267 | [Python] OpenCV 9-1. 색공간 바꾸기 | 푸딩뱃살 | 630 | 2020.06.02 23:27 |
266 | [Python] OpenCV 8-3. 이미지 비트 연산 | 푸딩뱃살 | 513 | 2020.06.02 23:21 |