[17] PHP - 파일 구조 갖추기

2024. 6. 10. 13:45PHP

728x90

[ 환경 ]
ㄴ php 7

※ 참고 https://kuk1938.tistory.com/39

 

[6] PHP - 파일 불러오기(include,require)

[ 환경 ] ㄴ php 7 ㄴ MySQL 5.7 ※ 최근 세션, 로그인, 로그아웃시에 각 페이지마다 session_start()를 사용해야 했다. ㄴ 이는 각 페이지마다 불 필요하게 코드가 계속 늘어나야 한다는 문제가 있다. 1. 함

kuk1938.tistory.com

 

※ 플러그인이나 css파일 연결을 할것이며, 공통으로 불러오는 파일들이 늘어나게 된다.

※ DB연결구문, 로그인세션 구문을 공통으로 불러오고 있고, 추가로 html구조를 공통화 할것이다.


1. setting파일(DB연결구문과 head)

ㄴ DB연결구문과 함께 공통으로 맞춘다.

<?php 
    // 설정페이지
	session_start(); // 세션 시작

	// DB연결 구문
	$host = "111.111.11.111";
	$user = "root";
	$password = "?????";
	$dbname = "?????";
	// $conn = mysqli_connect($host, $user, $password, $dbname); // 절차지향
	$conn = new mysqli($host, $user, $password, $dbname); // 객체지향
	$mysql_check = $conn->connect_error; // mysql에러확인

	if($mysql_check){ // db연결여부 확인 코드.
		die("연결실패 :".$mysql_check); // 연결 실패 원인 함께 출력
	}else{
		
	}
?>



<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>moonddev PHP 포스팅</title>

	<!-- 제이쿼리 플러그인 -->
	<script src="<?=$dir['main']?>plugin/jquery/jquery-latest.min.js"></script>
	<script src="<?=$dir['main']?>plugin/jquery-ui/jquery-ui.min.js"></script>
</head>
<body>

ㄴ setting.php로 따로 파일을 만들고 html,head,body태그 파일을 만든다.

ㄴ 제이쿼리 사용을 위해 제이쿼리 파일을 연결

ㄴ 추후에 css파일도 연결할 수 있다.

 

2. footer 파일 

ㄴ body,html 닫는 태그만 넣어준다.

 

3. index페이지에 코드 적용

<?php 
	require_once 'config.php';
	// session_destroy();
?>

<!DOCTYPE html>
<html>
<head>
	<title>로그인</title>
</head>
<body>
	<form method="POST" action="login.php" style="width:100%; float:left;">
		<div>
			아이디<input type="text" name="id">
			비밀번호<input type="password" name="password">
			<button type="submit">로그인</button>
		</div>
	</form>

	<div style="width:100%; float:left; padding:30px 0px;">
		<button type="submit">
			<a href="join.php" style="text-decoration: none; color:#000000; font-weight:bold;">회원가입</a>
		</button>
	</div>
</body>
</html>

ㄴ seeting, footer 적용 전

 

<?php 
	require_once 'include/setting.php';
	// session_destroy();
?>
<form method="POST" action="login.php" style="width:100%; float:left;">
	<div>
		아이디<input type="text" name="id">
		비밀번호<input type="password" name="password">
		<button type="submit">로그인</button>
	</div>
</form>

<div style="width:100%; float:left; padding:30px 0px;">
	<button type="submit">
		<a href="join.php" style="text-decoration: none; color:#000000; font-weight:bold;">회원가입</a>
	</button>
</div>
<?php require_once 'include/footer.php'; ?>

ㄴ seeting, footer 적용 후

 

4. 사이트 확인

 

ㄴ 제이쿼리 불러오는 파일 확인, 사이트 정상 확인

728x90

'PHP' 카테고리의 다른 글

[18] PHP - 회원 목록(게시판 목록)  (0) 2024.06.14
[16] PHP - 나의 정보 확인 및 수정  (0) 2024.06.10
[15] PHP - 회원가입(비밀번호 확인)  (0) 2024.06.07
[14] PHP - 회원가입  (1) 2024.06.07
[13] PHP - CURL 실제활용  (0) 2024.05.06