Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/Nhom_2_Web_Nang_Cao
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Try Out Development Containers: PHP

Team members:
"Nguyễn Mạnh Hưng",
"Văn Công Minh"

[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-php)

A **development container** is a running container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Dev Containers](https://aka.ms/vscode-remote/containers)**.
Expand Down
26 changes: 26 additions & 0 deletions baiTap/tuan1/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<title>Web n�ng cao</title>

</head>

<style>
body {
width: 300px;
}
</style>

<body>

<?php include('./login.php')?>

</body>

</html>
49 changes: 49 additions & 0 deletions baiTap/tuan1/logged_in.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<title>Web n�ng cao</title>

</head>

<style>
body {
width: 350px;
}
</style>

<body>

<form>
<div class="row mb-3">
<label class="col-sm-5 col-form-label">Tên đăng nhập là:</label>
<label class="col-sm-5 col-form-label">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
echo $username;
}
?>
</label>
</div>
<div class="row mb-3">
<label class="col-sm-5 col-form-label">Mật khẩu là:</label>
<label class="col-sm-5 col-form-label">
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$password = $_POST["password"];
echo $password;
}
?>
</label>
</div>
</form>

</body>

</html>
20 changes: 20 additions & 0 deletions baiTap/tuan1/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<form method="POST" action="logged_in.php">
<div class="row mb-3">
<label for="inputUsername" class="col-sm-5 col-form-label">Tên đăng nhập:</label>
<div class="col-sm-7">
<input type="text" name="username" class="form-control" id="inputUsername" required>
</div>
</div>
<div class="row mb-3">
<label for="inputPassword" class="col-sm-5 col-form-label">Mật khẩu:</label>
<div class="col-sm-7">
<input type="password" name="password" class="form-control" id="inputPassword" required>
</div>
</div>
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-5">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
51 changes: 51 additions & 0 deletions baiTap/tuan3/databases/db_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- --------------------------------------------------------
-- Host: 127.0.0.1
-- Server version: 11.3.2-MariaDB - mariadb.org binary distribution
-- Server OS: Win64
-- HeidiSQL Version: 12.6.0.6765
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


-- Dumping database structure for db_test
CREATE DATABASE IF NOT EXISTS `db_test` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */;
USE `db_test`;

-- Dumping structure for table db_test.images
CREATE TABLE IF NOT EXISTS `images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`path` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `path` (`path`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Dumping data for table db_test.images: ~0 rows (approximately)
DELETE FROM `images`;

-- Dumping structure for table db_test.users
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Dumping data for table db_test.users: ~0 rows (approximately)
DELETE FROM `users`;

INSERT INTO `users` (`id`, `username`, `password`) VALUES (1, 'admin', 'f865b53623b121fd34ee5426c792e5c33af8c227');

/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
8 changes: 8 additions & 0 deletions baiTap/tuan3/db_connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
// Kết nối với CSDL
$db = new mysqli('localhost', 'root', '', 'db_test');

if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
?>
22 changes: 22 additions & 0 deletions baiTap/tuan3/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
if($_SESSION["IsLogin"] == false)
header('Location: login.php');

if(isset($_POST['filename'])) {
$filename = 'uploads/' . $_POST['filename'];

if(file_exists($filename)){
unlink($filename);
}

include "db_connect.php";
$query = "DELETE FROM images WHERE path='$filename'";
if ($db->query($query) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $db->error;
}

header("Location: home.php");
}
?>
32 changes: 32 additions & 0 deletions baiTap/tuan3/filelist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
if($_SESSION["IsLogin"] == false)
header('Location: login.php');

$files = scandir('uploads/');
$files = array_diff($files, array('.', '..'));

if(isset($_GET['sortby'])) {
$sortby = $_GET['sortby'];
if($sortby == 'name') {
sort($files);
} elseif($sortby == 'date') {
usort($files, function($a, $b) {
return filemtime('uploads/' . $a) < filemtime('uploads/' . $b);
});
}
}

foreach($files as $file) {
echo 'File Name: ' . $file . '<br>';
echo 'File Type: ' . mime_content_type('uploads/' . $file) . '<br>';
echo 'Upload Time: ' . date ("F d Y H:i:s.", filemtime('uploads/' . $file)) . '<br>';
echo 'File Size: ' . filesize('uploads/' . $file) . '<br><br>';
echo '<form action="delete.php" method="POST">
<input type="hidden" name="filename" value="' . $file . '">
<input type="submit" value="Delete">
</form>';
}

echo '<a href="?sortby=name">Sort by Name</a><br>';
echo '<a href="?sortby=date">Sort by Date</a><br>';
?>
27 changes: 27 additions & 0 deletions baiTap/tuan3/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<?php
session_start();
if($_SESSION["IsLogin"] == false)
header('Location: login.php');
?>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tuần 3</title>
</head>
<body>
<?php
include "upload.php";
include 'filelist.php';
?>

<form method="POST" action="logout.php">
<div class="row">
<div class="col-sm-5">
<button type="submit" class="btn btn-primary">Đăng xuất</button>
</div>
</div>
</form>
</body>
</html>
40 changes: 40 additions & 0 deletions baiTap/tuan3/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<?php
session_start();
if($_SESSION["IsLogin"] == true)
header("Location: home.php");
?>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Đăng nhập</title>
</head>
<body>
<form method="POST" action="validateuser.php">
<div class="row mb-3">
<label for="inputUsername" class="col-sm-5 col-form-label">Tên đăng nhập:</label>
<div class="col-sm-7">
<input type="text" name="username" class="form-control" id="inputUsername" required>
</div>
</div>
<div class="row mb-3">
<label for="inputPassword" class="col-sm-5 col-form-label">Mật khẩu:</label>
<div class="col-sm-7">
<input type="password" name="password" class="form-control" id="inputPassword" required>
</div>
</div>
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-5">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
<?php
if(isset($_GET['error'])) {
echo '<script>alert("' . $_GET['error'] . '");</script>';
}
?>
</body>
</html>
5 changes: 5 additions & 0 deletions baiTap/tuan3/logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
session_start();
$_SESSION["IsLogin"] = false;
header("Location: login.php");
?>
49 changes: 49 additions & 0 deletions baiTap/tuan3/upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
if($_SESSION["IsLogin"] == false)
header('Location: login.php');
?>

<form action="upload.php" method="POST" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload File" name="submit">
</form>
<form action="home.php">
<input type="submit" value="Danh sách file">
</form>

<?php
if(isset($_POST["submit"])) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded.";

include "db_connect.php";
$result = $db->query("SELECT MAX(id) AS max_id FROM images");

if ($result->num_rows > 0) {
$row = $result->fetch_assoc();

$max_id = $row['max_id'];

if (isset($max_id)) {
$_SESSION['index'] = $max_id + 1;
} else {
$_SESSION['index'] = 1;
}
} else {
$_SESSION['index'] = 1;
}
$id = $_SESSION['index'];
$query = "INSERT INTO images (id, path) VALUES ('$id', '$target_file')";
if ($db->query($query) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $query . "<br>" . $db->error;
}
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
Binary file added baiTap/tuan3/uploads/dog_hehe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading