일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 제이쿼리연결
- 한글잘림
- 자바스크립트 배열 할당
- 기획자랑 사이좋게 지내고 싶다
- max apache
- 객체지향
- 한글입력 씹힘
- 닐 스미스 지음
- jquery 사용하기
- 맥 mysql
- python tkinter 인터페이스
- 황반석 옮김
- 자바스크립트 객체
- 자바스크립트 class
- 한글입력 잘림
- 배열 분해 할당
- python GUI 사용하기
- 맥 아파치
- 핵심만 골라 배우는 SwiftUI 기반의 iOS 프로그래밍
- 한글입력 오류
- 객체
- 한글입력 안됨
- 생활코딩
- 제이펍 출판
- 자바스크립트
- 자바스크립트 객체 만들기
- 비주얼스튜디오 코드
- SwiftUI 기반의 iOS 프로그래밍
- max MySQL
- 블록 스코프
- Today
- Total
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 제이쿼리연결
- 한글잘림
- 자바스크립트 배열 할당
- 기획자랑 사이좋게 지내고 싶다
- max apache
- 객체지향
- 한글입력 씹힘
- 닐 스미스 지음
- jquery 사용하기
- 맥 mysql
- python tkinter 인터페이스
- 황반석 옮김
- 자바스크립트 객체
- 자바스크립트 class
- 한글입력 잘림
- 배열 분해 할당
- python GUI 사용하기
- 맥 아파치
- 핵심만 골라 배우는 SwiftUI 기반의 iOS 프로그래밍
- 한글입력 오류
- 객체
- 한글입력 안됨
- 생활코딩
- 제이펍 출판
- 자바스크립트
- 자바스크립트 객체 만들기
- 비주얼스튜디오 코드
- SwiftUI 기반의 iOS 프로그래밍
- max MySQL
- 블록 스코프
- Today
- Total
java,javascript,android,php,sql,공부용,메모용
php / mac에서 php 코딩하기 / 로그인,회원가입 페이지 만들기 - 2 본문
https://tog-code.tistory.com/91?category=444725
이어서
php / mac에서 php 코딩하기 / 로그인,회원가입 페이지 만들기 - 2
- DB 페이지와 password 암호화 페이지
db.php, password.php
모든 페이지는 db 정보를 인크루드 함
회원가입 암호화를 위해서 member_ok.php sql에 올려주는 페이지에서는 암호화하는 password.php를 가져옴
db.php
이곳에 함수로 mq($sql) 이라고 만든게 DB접속과 관련있다 이 내용을 계속 다른곳에 인크루드한다.
<?php
session_start();
$db = new mysqli("localhost","root","root","young");
$db -> set_charset("utf8");
function mq($sql){
global $db;
return $db->query($sql);
}
?>
php 5.5 비밀번호 라이브러리
password.php
https://www.php.net/manual/en/function.password-hash.php
참고용 링크 길어서 접어둠 접은글 클릭
<?php
/**
* A Compatibility library with PHP 5.5's simplified password hashing API.
*
* @author Anthony Ferrara <ircmaxell@php.net>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @copyright 2012 The Authors
*/
namespace {
if (!defined('PASSWORD_BCRYPT')) {
/**
* PHPUnit Process isolation caches constants, but not function declarations.
* So we need to check if the constants are defined separately from
* the functions to enable supporting process isolation in userland
* code.
*/
define('PASSWORD_BCRYPT', 1);
define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
define('PASSWORD_BCRYPT_DEFAULT_COST', 10);
}
if (!function_exists('password_hash')) {
/**
* Hash the password using the specified algorithm
*
* @param string $password The password to hash
* @param int $algo The algorithm to use (Defined by PASSWORD_* constants)
* @param array $options The options for the algorithm to use
*
* @return string|false The hashed password, or false on error.
*/
function password_hash($password, $algo, array $options = array()) {
if (!function_exists('crypt')) {
trigger_error("Crypt must be loaded for password_hash to function", E_USER_WARNING);
return null;
}
if (is_null($password) || is_int($password)) {
$password = (string) $password;
}
if (!is_string($password)) {
trigger_error("password_hash(): Password must be a string", E_USER_WARNING);
return null;
}
if (!is_int($algo)) {
trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING);
return null;
}
$resultLength = 0;
switch ($algo) {
case PASSWORD_BCRYPT:
$cost = PASSWORD_BCRYPT_DEFAULT_COST;
if (isset($options['cost'])) {
$cost = (int) $options['cost'];
if ($cost < 4 || $cost > 31) {
trigger_error(sprintf("password_hash(): Invalid bcrypt cost parameter specified: %d", $cost), E_USER_WARNING);
return null;
}
}
// The length of salt to generate
$raw_salt_len = 16;
// The length required in the final serialization
$required_salt_len = 22;
$hash_format = sprintf("$2y$%02d$", $cost);
// The expected length of the final crypt() output
$resultLength = 60;
break;
default:
trigger_error(sprintf("password_hash(): Unknown password hashing algorithm: %s", $algo), E_USER_WARNING);
return null;
}
$salt_req_encoding = false;
if (isset($options['salt'])) {
switch (gettype($options['salt'])) {
case 'NULL':
case 'boolean':
case 'integer':
case 'double':
case 'string':
$salt = (string) $options['salt'];
break;
case 'object':
if (method_exists($options['salt'], '__tostring')) {
$salt = (string) $options['salt'];
break;
}
case 'array':
case 'resource':
default:
trigger_error('password_hash(): Non-string salt parameter supplied', E_USER_WARNING);
return null;
}
if (PasswordCompat\binary\_strlen($salt) < $required_salt_len) {
trigger_error(sprintf("password_hash(): Provided salt is too short: %d expecting %d", PasswordCompat\binary\_strlen($salt), $required_salt_len), E_USER_WARNING);
return null;
} elseif (0 == preg_match('#^[a-zA-Z0-9./]+$#D', $salt)) {
$salt_req_encoding = true;
}
} else {
$buffer = '';
$buffer_valid = false;
if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) {
$buffer = mcrypt_create_iv($raw_salt_len, MCRYPT_DEV_URANDOM);
if ($buffer) {
$buffer_valid = true;
}
}
if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) {
$strong = false;
$buffer = openssl_random_pseudo_bytes($raw_salt_len, $strong);
if ($buffer && $strong) {
$buffer_valid = true;
}
}
if (!$buffer_valid && @is_readable('/dev/urandom')) {
$file = fopen('/dev/urandom', 'r');
$read = 0;
$local_buffer = '';
while ($read < $raw_salt_len) {
$local_buffer .= fread($file, $raw_salt_len - $read);
$read = PasswordCompat\binary\_strlen($local_buffer);
}
fclose($file);
if ($read >= $raw_salt_len) {
$buffer_valid = true;
}
$buffer = str_pad($buffer, $raw_salt_len, "\0") ^ str_pad($local_buffer, $raw_salt_len, "\0");
}
if (!$buffer_valid || PasswordCompat\binary\_strlen($buffer) < $raw_salt_len) {
$buffer_length = PasswordCompat\binary\_strlen($buffer);
for ($i = 0; $i < $raw_salt_len; $i++) {
if ($i < $buffer_length) {
$buffer[$i] = $buffer[$i] ^ chr(mt_rand(0, 255));
} else {
$buffer .= chr(mt_rand(0, 255));
}
}
}
$salt = $buffer;
$salt_req_encoding = true;
}
if ($salt_req_encoding) {
// encode string with the Base64 variant used by crypt
$base64_digits =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
$bcrypt64_digits =
'./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$base64_string = base64_encode($salt);
$salt = strtr(rtrim($base64_string, '='), $base64_digits, $bcrypt64_digits);
}
$salt = PasswordCompat\binary\_substr($salt, 0, $required_salt_len);
$hash = $hash_format . $salt;
$ret = crypt($password, $hash);
if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != $resultLength) {
return false;
}
return $ret;
}
/**
* Get information about the password hash. Returns an array of the information
* that was used to generate the password hash.
*
* array(
* 'algo' => 1,
* 'algoName' => 'bcrypt',
* 'options' => array(
* 'cost' => PASSWORD_BCRYPT_DEFAULT_COST,
* ),
* )
*
* @param string $hash The password hash to extract info from
*
* @return array The array of information about the hash.
*/
function password_get_info($hash) {
$return = array(
'algo' => 0,
'algoName' => 'unknown',
'options' => array(),
);
if (PasswordCompat\binary\_substr($hash, 0, 4) == '$2y$' && PasswordCompat\binary\_strlen($hash) == 60) {
$return['algo'] = PASSWORD_BCRYPT;
$return['algoName'] = 'bcrypt';
list($cost) = sscanf($hash, "$2y$%d$");
$return['options']['cost'] = $cost;
}
return $return;
}
/**
* Determine if the password hash needs to be rehashed according to the options provided
*
* If the answer is true, after validating the password using password_verify, rehash it.
*
* @param string $hash The hash to test
* @param int $algo The algorithm used for new password hashes
* @param array $options The options array passed to password_hash
*
* @return boolean True if the password needs to be rehashed.
*/
function password_needs_rehash($hash, $algo, array $options = array()) {
$info = password_get_info($hash);
if ($info['algo'] !== (int) $algo) {
return true;
}
switch ($algo) {
case PASSWORD_BCRYPT:
$cost = isset($options['cost']) ? (int) $options['cost'] : PASSWORD_BCRYPT_DEFAULT_COST;
if ($cost !== $info['options']['cost']) {
return true;
}
break;
}
return false;
}
/**
* Verify a password against a hash using a timing attack resistant approach
*
* @param string $password The password to verify
* @param string $hash The hash to verify against
*
* @return boolean If the password matches the hash
*/
function password_verify($password, $hash) {
if (!function_exists('crypt')) {
trigger_error("Crypt must be loaded for password_verify to function", E_USER_WARNING);
return false;
}
$ret = crypt($password, $hash);
if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != PasswordCompat\binary\_strlen($hash) || PasswordCompat\binary\_strlen($ret) <= 13) {
return false;
}
$status = 0;
for ($i = 0; $i < PasswordCompat\binary\_strlen($ret); $i++) {
$status |= (ord($ret[$i]) ^ ord($hash[$i]));
}
return $status === 0;
}
}
}
namespace PasswordCompat\binary {
if (!function_exists('PasswordCompat\\binary\\_strlen')) {
/**
* Count the number of bytes in a string
*
* We cannot simply use strlen() for this, because it might be overwritten by the mbstring extension.
* In this case, strlen() will count the number of *characters* based on the internal encoding. A
* sequence of bytes might be regarded as a single multibyte character.
*
* @param string $binary_string The input string
*
* @internal
* @return int The number of bytes
*/
function _strlen($binary_string) {
if (function_exists('mb_strlen')) {
return mb_strlen($binary_string, '8bit');
}
return strlen($binary_string);
}
/**
* Get a substring based on byte limits
*
* @see _strlen()
*
* @param string $binary_string The input string
* @param int $start
* @param int $length
*
* @internal
* @return string The substring
*/
function _substr($binary_string, $start, $length) {
if (function_exists('mb_substr')) {
return mb_substr($binary_string, $start, $length, '8bit');
}
return substr($binary_string, $start, $length);
}
/**
* Check if current PHP version is compatible with the library
*
* @return boolean the check result
*/
function check() {
static $pass = NULL;
if (is_null($pass)) {
if (function_exists('crypt')) {
$hash = '$2y$04$usesomesillystringfore7hnbRJHxXVLeakoG8K30oukPsA.ztMG';
$test = crypt("password", $hash);
$pass = $test == $hash;
} else {
$pass = false;
}
}
return $pass;
}
}
}
?>
회원가입 로그인 템플릿 검색했다
https://codepen.io/joshsorosky/pen/gaaBoB
Log in/Sign up screen animation
Little form flow based on a design by www.100daysui.com/ Checkbox from codepen.io/CreativeJuiz/...
codepen.io
위 템플릿을 나에게 맞게 수정해서 사용했다 나는 로그인과 회원가입 창을 분리시킴
현재 페이지 구성
- 로그인 페이지 (member_login.php)
sign_in.php
- 로그인 누르면 id password 확인하는 페이지 (login_ok.php)
signin_ok.php
- 로그아웃 페이지 (logout.php)
- 로그인 확인 페이지 (main.php)
- 회원가입 페이지 (member.php)
signin_up.php
- 아이디, 비밀번호 체크 페이지
sign_id_check.php
- 회원가입하면 이동되는 페이지 (여기서 정보를 매칭하고 sql에 올려주는 역활 중요함***)
signup_ok.php
회원가입 signin_up.php
<?php include "db.php"; ?>
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>회원가입</title>
<link rel="stylesheet" type="text/css" href="../css/mem_common.css" />
<!-- jQuery 3.3.1 -->
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>-->
<script src="../js/jquery.min.js"></script>
<!-- <script type="text/javascript" src="../js/jquery-3.2.1.js"></script> -->
<script>
$(document).ready(function(e) {
$(".check").on("keyup", function(){ //check라는 클래스에 입력을 감지
var self = $(this);
var userid;
if(self.attr("id") === "userid"){
userid = self.val();
}
$.post( //post방식으로 id_check.php에 입력한 userid값을 넘깁니다
"sign_id_check.php",
{ userid : userid },
function(data){
if(data){ //만약 data값이 전송되면
self.parent().parent().find("#id_check").html(data); //div태그를 찾아 html방식으로 data를 뿌려줍니다.
self.parent().parent().find("#id_check").css("color", "#F00"); //div 태그를 찾아 css효과로 빨간색을 설정합니다
}
}
);
});
$(function(){
$("#alert-success").hide();
$("#alert-danger").hide();
$("input").keyup(function(){
var pwd1=$("#pwd1").val();
var pwd2=$("#pwd2").val();
if(pwd1 != "" || pwd2 != ""){
if(pwd1 == pwd2){
$("#alert-success").show();
$("#alert-danger").hide();
$("#submit").removeAttr("disabled");
}else{
$("#alert-success").hide();
$("#alert-danger").show();
$("#alert-danger").css("color","#F00");
$("#submit").attr("disabled", "disabled");
}
}
});
});
});
</script>
</head>
<body>
<!-- https://codepen.io/joshsorosky/pen/gaaBoB -->
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700' rel='stylesheet' type='text/css'>
<div class="container">
<div class="frame">
<div class="nav">
<ul class"links">
<li class="signin-active">회원가입</li>
</ul>
</div>
<!-- 아이디 이메일 비밀번호 이름 폰번호 (주소패스) -->
<form class="form-signin" action="../member/signup_ok.php" method="post" name="memform">
<label for="fullid">아이디  <span id="id_check"></span></label>
<input id="userid" class="form-styling check" type="text" name="userid" placeholder="" required />
<label for="email">이메일</label>
<input class="form-styling" type="text" name="useremail" placeholder=""/>
<label for="password">비밀번호</label>
<input id="pwd1" class="form-styling" type="text" name="password" placeholder=""/>
<label for="confirmpassword">비밀번호 확인  
<span class="alert alert-success" id="alert-success">비밀번호가 일치합니다.</span>
<span styld="color:#F00;" class="alert alert-danger" id="alert-danger">비밀번호가 일치하지 않습니다.</span>
</label>
<input id="pwd2" class="form-styling" type="text" name="confirmpassword" placeholder=""/>
<label for="username">이름</label>
<input class="form-styling" type="text" name="username" placeholder=""/>
<label for="userph">핸드폰</label>
<input class="form-styling" type="text" name="userph" placeholder=""/>
<input class="btn-signup" type="submit" value="가입하기" />
</form>
</div>
</div>
</body>
</html>
아이디 실시간 체크 페이지 sign_id_check.php
<?php
include "../db.php";
if($_POST['userid'] != NULL){
$id_check = mq("select * from y_member where mem_id='{$_POST['userid']}'");
$id_check = $id_check->fetch_array();
if($id_check >= 1){
echo "이미 가입된 아이디입니다.";
} else {
//echo "사용할 수 있습니다.";
}
} ?>
나도 한번에 작성하고 그런거 아니다.. 검색하고 여러 문서들을 살피고 다른 사람들이 쓴 블로그를 살쳐보고 여러번의 시행착오를 거쳐서 실패를 거듭하다가 깨닫고 했다 그치만 여전히 머릿속에서는 복잡하다 ㅠㅠ 확실히 누군가 알려주는 방식이 더 편리하긴 하다... 혼자는 오래걸린다
post 방식으로 id를 넘겨서 받은 아이디를 불러와서 sql문으로 id에 맞는 데이터베이스랑 매칭해서 있는지 없는지 검사하는 구문
fetch_array() 라는 함수를 주의깊게 보면 좋을거 같다 다른분이 써둔 글을 참고해서 접은글에 써둠
fetch_row, fetch_assoc, fetch_array, fetch_object.
네 함수 모두 공통적으로 mysql에 저장되어 있는 데이터베이스 들을 배열 또는 객체로 추출해 오는 함수다.
다음과 같은 DB가 있을때
(테이블명 : student)
필드명 | name | age |
저장값 | 김헤키 | 21 |
<fetch_row> - 숫자 인덱스로 배열을 반환.
Array (
[0] -> 김헤키
[1] -> 21
)
<fetch_assoc> - 필드명을 인덱스로 배열을 반환.
Array (
[name] -> 김헤키
[age] -> 21
)
<fetch_array> - 숫자, 필드명 인덱스로 배열을 반환.
Array (
[0] -> 김헤키
[name] -> 김헤키
[1] -> 21
[age] -> 21
)
<fetch_object> - 필드명 인덱스를 가진 객체를 반환.
stdClass Object (
[name] => CUFFS
[value] => アメサラサ
)
$conn = mysqli_connect( // mysql 접속
'서버명'
'MYSQL의ID'
'MYSQL의 패스워드'
'사용할DB 이름'
); // = $db = new mysqli("localhost","root","root","young");
$sql = "SELECT * FROM student";
$result = mysqli_query($conn,$sql); // mysqli 에 쿼리문을 넣어준다.
$data = mysqli_fetch_<row or assoc or array or object>($result); // 4개 함수중에 한개를 선택
fetch_row 는 $data[0] => 김헤키 $row[1] => 21
fetch_assoc 은 $data['name'] => 김헤키 $data['age'] => 21
fetch_array 는 위 둘다 가능
fetch_object 는 $data->name => 김헤키 $data->age => 21
* 속도는 fetch_object > fetch_array > fetch_assoc > fetch_row 순으로 느리다고 한다.
출처: https://programming119.tistory.com/10 [개발자 아저씨들 힘을모아]
아이디 비밀번호 한번 더 확인하고 회원가입으로 넘기는 페이지 signup_ok.php
<?php
include "../db.php";
include "../password.php";
$userid = $_POST['userid'];
$email = $_POST['useremail'];
$userpw = password_hash($_POST['password'], PASSWORD_DEFAULT);
$username = $_POST['username'];
$userph = $_POST['userph'];
// $adress = $_POST['adress'];
// $sex = $_POST['sex'];
// $email = $_POST['email'].'@'.$_POST['emadress'];
$id_check = mq("select * from y_member where mem_id = '$userid'");
$id_check = $id_check->fetch_array();
if($id_check >= 1){
echo "<script>alert('아이디가 중복됩니다.'); history.back();</script>";
}else{
$sql = mq("insert into y_member (mem_id,mem_email,mem_password,mem_username,mem_phone)
values('".$userid."','".$email."','".$userpw."','".$username."','".$userph."')");
?>
<meta charset="utf-8" />
<script type="text/javascript">
alert('회원가입이 완료되었습니다.');
location.href = '../index0.php';
</script>
<meta http-equiv="refresh" content="0 url=/">
<?php } ?>
회원가입 끝
로그인 sign_in.pnp
<?php include "db.php"; ?>
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>로그인</title>
<link rel="stylesheet" type="text/css" href="../css/mem_in_common.css" />
<script src="../js/jquery.min.js"></script>
</head>
<body>
<!-- https://codepen.io/joshsorosky/pen/gaaBoB -->
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700' rel='stylesheet' type='text/css'>
<div class="container">
<div class="frame">
<div class="nav">
<ul class"links">
<li class="signin-active">로그인</li>
<!-- <li class="signin-active"><a class="btn">로그인</a></li>
<li class="signup-inactive"><a class="btn">회원가입</a></li> -->
</ul>
</div>
<div ng-app ng-init="checked = false">
<form class="form-signin" action="../member/signin_ok.php" method="post" name="memform">
<label for="userid">아이디</label>
<input class="form-styling" type="text" name="userid" placeholder=""/>
<label for="password">비밀번호</label>
<input class="form-styling" type="text" name="password" placeholder=""/>
<input type="checkbox" id="checkbox"/>
<label for="checkbox" ><span class="ui"></span>Keep me signed in</label>
<input class="btn-signup" type="submit" value="로그인" />
</form>
</div>
</div>
</body>
</html>
로그인 버튼 누르면 id와 password 확인하는 페이지 signin_ok.php
<meta charset="utf-8" />
<?php
include "../db.php";
include "../password.php";
//POST로 받아온 아이다와 비밀번호가 비었다면 알림창을 띄우고 전 페이지로 돌아갑니다.
if($_POST["userid"] == "" || $_POST["password"] == ""){
echo '<script> alert("아이디나 패스워드 입력하세요"); history.back(); </script>';
}else{
//password변수에 POST로 받아온 값을 저장하고 sql문으로 POST로 받아온 아이디값을 찾습니다.
$password = $_POST['password'];
$sql = mq("select * from y_member where mem_id='".$_POST['userid']."'");
$member = $sql->fetch_array();
$hash_pw = $member['mem_password']; //$hash_pw에 POSt로 받아온 아이디열의 비밀번호를 저장합니다.
if(password_verify($password, $hash_pw)) //만약 password변수와 hash_pw변수가 같다면 세션값을 저장하고 알림창을 띄운후 main.php파일로 넘어갑니다.
{
$_SESSION['userid'] = $member["mem_id"];
$_SESSION['password'] = $member["mem_password"];
$_SESSION['level'] = $member["mem_level"];
echo "<script>alert('로그인되었습니다.'); location.href='../page/main.php';</script>";
}else{ // 비밀번호가 같지 않다면 알림창을 띄우고 전 페이지로 돌아갑니다
echo "<script>alert('아이디 혹은 비밀번호를 확인하세요.'); history.back();</script>";
}
}
?>
마지막에 password 변수와 hash_pw 변수가 같으면 세션값을 저장하는곳이 있다
거기서 나중에 level 값을 사용하려고 level 값도 세션에 저장했다 (회원 등급)
- 로그아웃 페이지 (logout.php)
<?php
include "../db.php";
session_destroy();
?>
<meta charset="utf-8">
<script>alert("로그아웃되었습니다."); location.href="../index0.php"; </script>
- 로그인 확인 페이지 (main.php)
<?php include "../db.php"; ?>
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>메인페이지</title>
</head>
<body>
<?php
var_dump( $_SESSION ); // 세션에 저장된 모든 값 확인
echo session_id(); // 세션에 저장된 id 값 확인
echo $_SESSION[ 'userid' ]; // 세션에 저장된 userid 확인
if(isset($_SESSION['userid'])){
echo "<h2>{$_SESSION['userid']} 님 환영합니다.</h2>";
echo "<h2>{$_SESSION['level']} 레벨 확인</h2>";
?>
<a href="../member/logout.php"><input type="button" value="로그아웃" /></a>
<?php
}else{
echo "<script>alert('잘못된 접근입니다.'); history.back();</script>";
}
?>
</body>
</html>
로그인 확인하는 main.php 라는 페이지에서 세션에 저장된 값들을 확인해봤다
메인페이지에 로그인하는 부분을 만들었다
회원가이 로그인 부분에 추가로 해야하는 부분
1. 로그인 후 로그인 여부에 따른 로그아웃으로 변경되도록 로그인 로그아웃 두개로 만들기
2. 회원가입시에 패스워드 * 모양으로 나타나게 변경 (input type="password" 로 변경)
회원가입 버튼은 따로 나타내지 않을 예정
- 창 줄어들면 햄버거 메뉴에서 로그인하는 버튼도 추가 (완료)
- 개인적으로 사용할 용도이기 때문에 다 만들고 나면 회원가입을 막아두거나 넘어가지 않도록 또는 레벨을 모두 지정해두고 사용하지 못하도록 할 예정
'개발 > php' 카테고리의 다른 글
XAMPP 코드이그나이터4 로컬 설치 메인화면 확인하기 Whoops! 해결 (0) | 2023.01.22 |
---|---|
코드이그나이터4 CI4 view url 연결 자동라우팅 설정 (0) | 2023.01.22 |
php / mac에서 php 코딩하기 / 로그인,회원가입 페이지 만들기-1 / MySQL 프로그램/ ERD 프로그램 (0) | 2021.10.25 |
php / 맥에서 아파치 사용하기/ 맥에서 코딩하기 / APMSETUP 대체 AutoSet 설치 / MAMP 설치 환경설정 등 (0) | 2021.10.21 |
php count (php에서의 length), 소수점 처리하기 round 합계 평균 1차배열, 2차배열, key value로 지정 (0) | 2021.04.13 |