회원 로그인
|
클래스
PHP 클래스
:로그인 (ID/패스워드)
class1.php
class2.php
class3.php
:로그인 (ID/패스워드)
class1.php
<?php // 기본 클래스 선언 및 객체 생성 // 클래스 선언 // class 클래스명 class GameUser { // 멤버 변수 선언 var $id = "user"; var $pw = "0000"; // 메소드 선언 // 유저 정보 설정 function RequestUserInfo() { $id = $_POST["user_id"]; $pw = $_POST["user_pw"]; // $this->id = $id; $this->pw = $pw; } // 유저 정보 보기 function ResponseUserInfo() { // 결과 딕셔너리 생성 $response_data = array( "id" => $this->id, "pw" => $this->pw ); //배열을 json으로 인코딩해서 응답함 echo json_encode($response_data); } } // php 객체 생성 $user = new GameUser(); // 유저 정보 요청 받음 $user->RequestUserInfo(); // 유저 정보 응답 해줌 $user->ResponseUserInfo(); ?>
class2.php
<?php // php 상속 예제 // 클래스 선언 // class 클래스명 class User { // 멤버 변수 선언 var $id = "user"; var $pw = "0000"; // 메소드 선언 // 유저 정보 설정 function RequestUserInfo() { $id = $_POST["user_id"]; $pw = $_POST["user_pw"]; $this--->id = $id; $this->pw = $pw; } // 유저 정보 보기 function ResponseUserInfo() { // 결과 딕셔너리 생성 $response_data = array( "id" => $this->id, "pw" => $this->pw ); // 배열을 json으로 인코딩해서 응답함 echo json_encode($response_data); } } // User 클래스를 상속함 GameUser 클래스를 선언함 class GameUser extends User { // 자식 클래스 멤버 추가 var $playTime = "0"; // 자식 클래스 메소드 추가 function RequestGameUserInfo() { // parent 키워드를 통해 부모 메소드를 호출 parent::RequestUserInfo(); // 자식 멤버 변수값 설정 $this->playTime = $_POST["play_time"]; } // 부모 메소드를 오버라이드 함 function ResponseUserInfo() { // 결과 딕셔너리 생성 $response_data = array( "id" => $this->id, "pw" => $this->pw, "playTime" => $this->playTime ); // 배열을 json으로 인코딩해서 응답함 echo json_encode($response_data); } } // PHP 객체 생성 $user = new GameUser(); // 게임 유저 정보 요청 받음 $user->RequestGameUserInfo(); // 게임 유저 정보 응답 해줌 $user->ResponseUserInfo(); ?>
class3.php
<?php // 생성자 사용 // 클래스 선언 // class 클래스명 class User { // 멤버 변수 선언 var $id = "user"; var $pw = "0000"; // 생성자 function __construct($id, $pw) { $this--->id = $id; $this->pw = $pw; } // 유저 정보 보기 function ResponseUserInfo() { // 결과 딕셔너리 생성 $response_data = array( "id" => $this->id, "pw" => $this->pw ); // 배열을 json으로 인코딩해서 응답함 echo json_encode($response_data); } } // User 클래스를 상속함 GameUser 클래스를 선언함 class GameUser extends User { // 자식 클래스 멤버 추가 var $playTime = "0"; // GameUser 클래스의 생성자 (__construct) function __construct($id, $pw, $playTime) { // 부모 생성자를 호출함 parent::__construct($id, $pw); $this->playTime = $playTime; } // function __desctruct() { ... } 소멸자 // 부모 메소드를 오버라이드 함 function ResponseUserInfo() { // 결과 딕셔너리 생성 $response_data = array( "id" => $this->id, "pw" => $this->pw, "playTime" => $this->playTime ); // 배열을 json으로 인코딩해서 응답함 echo json_encode($response_data); } } $id = $_POST["user_id"]; $pw = $_POST["user_pw"]; $playTime = $_POST["play_time"]; // $user = new User($id, $pw); // PHP 객체의 생성자 호출 및 객체 생성 $user = new GameUser($id, $pw, $playTime); // 게임 유저 정보 응답 해줌 $user->ResponseUserInfo(); ?>
댓글 0개
| 엮인글 0개
285개(6/15페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
185 | [PHP] 회원가입 + 로그인 스크립트 (with Unity) [2+1] | 푸딩뱃살 | 12240 | 2015.12.06 17:31 |
184 | [C#] C# 추천 서적 | 푸딩뱃살 | 1321 | 2015.12.06 17:16 |
183 | [C/C++] C++ 참고 사이트 | 푸딩뱃살 | 1182 | 2015.12.04 16:13 |
>> | [PHP] 클래스 | 푸딩뱃살 | 3581 | 2015.12.04 14:40 |
181 | [PHP] CodeIgniter(코드이그나이트) | 푸딩뱃살 | 2932 | 2015.12.04 14:40 |
180 | [C#] Delegate (델리게이트) (with Unity) | 푸딩뱃살 | 6267 | 2015.12.01 10:44 |
179 | [PHP] php 함수 | 푸딩뱃살 | 2219 | 2015.11.30 15:33 |
178 | [PHP] Dictionary (딕셔너리) | 푸딩뱃살 | 2869 | 2015.11.27 12:37 |
177 | [PHP] 배열 | 푸딩뱃살 | 2170 | 2015.11.27 12:37 |
176 | [PHP] 변수 선언 / 산술 연산 | 푸딩뱃살 | 2183 | 2015.11.27 11:14 |
175 | [C#] Dictionary (딕셔너리) (with Unity) [3+3] | 푸딩뱃살 | 14483 | 2015.11.25 10:29 |
174 | [C#] List (리스트) (with Unity) | 푸딩뱃살 | 12088 | 2015.11.24 10:22 |
173 | [C#] Generic (제네릭) (with Unity) | 푸딩뱃살 | 4889 | 2015.11.22 12:32 |
172 | [C/C++] Templete (템플릿) | 푸딩뱃살 | 2045 | 2015.11.22 12:15 |
171 | [C#] 키보드 입력 | 푸딩뱃살 | 3570 | 2015.11.21 18:00 |
170 | [C#] 예외와 예외 처리 | 푸딩뱃살 | 4124 | 2015.11.21 17:39 |
169 | [C#] Struct (구조체) (with Unity) | 푸딩뱃살 | 5123 | 2015.11.18 22:08 |
168 | [C#] Property (프로퍼티) (with Unity) | 푸딩뱃살 | 2443 | 2015.11.18 10:50 |
167 | [C#] interface (인터페이스) (with Unity) | 푸딩뱃살 | 3308 | 2015.11.15 17:32 |
166 | [C#] 스트림 (stream) - 문자, 바이너리 읽기/쓰기 | 푸딩뱃살 | 12780 | 2015.11.14 18:24 |