php 게시판 만들기
- 공유 링크 만들기
- 이메일
- 기타 앱
php 게시판 만들기
php 게시판 만들기 (칼리리눅스 환경)
- php를 이용하여 기본적인 기능만 가지고 게시판을 만들려고 합니다.
- mysql을 이용하여 데이터베이스 설정하는 부분은 다음 포스팅에 진행하겠습니다.
- 일단 php를 이용하여 작성한 게시판 코드입니다.
- 리눅스 환경에서 경로는 /var/www/html 에서 파일을 생성하였습니다.
- vi /etc/apache2/mods-available/dir.conf 명령을 통해서 dir.conf에 index.php를 추가였습니다.
*** 출처 : 어서와 해킹은 처음이지 - 칼리리눅스로 배우는 해킹과 보안
*** index.php - 시작화면
Username : Password :
number title name date
*** login.php - 로그인창
alert('Invalid username or password');"; else{ session_start(); $_SESSION['username']=$username; } } else{ session_start(); session_destroy(); } ?>
*** file.php - 파일 업로드
if(!move_uploaded_file($file['tmp_name'],$file_name)) die('alert("file upload fail!");history.back()'); return $file_name; }
function file_download($file_path) { if(file_exists($file_path)){ $file_name = substr(strstr($file_path,'@'),2);
header('Content-Type: file/unknown'); header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename="'.$file_name.'"'); header('Content-Length:'.filesize($file_path)); header('Pragma: no-cache'); header('Expires:0');
readfile($file_path); exit; } } ?>
*** write.php - 게시글 작성
if(isset($_POST['write'])){ $username=$_POST['username']; $title=$_POST['title']; $comment=$_POST['comment']; $date=date("Y-m-d"); $file=NULL;
if(is_uploaded_file($_FILES['upfile']['tmp_name'])) $file=file_upload($_FILES['upfile']);
$con=mysqli_connect('localhost','root','toor','sample'); $result = mysqli_query($con, "INSERT INTO board(user,title,comment,file,date) VALUES('$username','$title','$comment','$file','$date')");
if(!$result) echo "alert('fail save comment');"; ?>
subject name " ?>
content attachment
*** view.php - 게시판 보기
if(!isset($_GET["id"])){ echo "alert('Invalid access page');"; echo ""; }
$id=$_GET['id']; $con=mysqli_connect('localhost', 'root','toor','sample'); $result=mysqli_query($con,"SELECT * FROM board WHERE id=".$id); if(mysqli_num_rows($result)==0){ echo "alert('Invalid access page');"; echo ""; } $row = mysqli_fetch_array($result) ?> subject name content
","", $row[comment])?> attachment ".substr(strstr($row[file],'@'),1).""; ?>
*** download.php - 파일 다운로드
- 이렇게 파일을 추가한 후 apache와 mysql을 실행합니다. (다음 포스팅에서 데이터베이스 생성을 올리겠습니다.)
#service apache2 start #service mysql start
** index.php - 시작화면
** 게시글 쓰기
** 게시글 보기
from http://lopicit.tistory.com/272 by ccl(A) rewrite - 2020-03-07 03:20:27
- 공유 링크 만들기
- 이메일
- 기타 앱
댓글
댓글 쓰기