Skip to content
Open

wp #52

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
17 changes: 17 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM mcr.microsoft.com/devcontainers/php:1-8.2-bookworm

# Install MariaDB client
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y mariadb-client \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Install php-mysql driver
RUN docker-php-ext-install mysqli pdo pdo_mysql

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

52 changes: 30 additions & 22 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/php
// README at: https://github.com/devcontainers/templates/tree/main/src/php-mariadb
{
<<<<<<< HEAD
"name": "PHP & MariaDB",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
=======
"name": "PHP",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/php:1-8.3",
>>>>>>> 9c4c759e95499bb57be2a35e2e0c55f292036908

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
"settings": {},
"extensions": [
"streetsidesoftware.code-spell-checker"
]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [8000],

// Use 'portsAttributes' to set default properties for specific forwarded ports. More info: https://code.visualstudio.com/docs/remote/devcontainerjson-reference.
"portsAttributes": {
"8000": {
"label": "Hello Remote World",
"onAutoForward": "notify"
}
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
"extensions": [
"ikappas.composer"
]
}
},

// For use with PHP or Apache (e.g.php -S localhost:8080 or apache2ctl start)
"forwardPorts": [
8080,
3306
],
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html; if [ -f composer.json ];then composer install;fi"

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
36 changes: 36 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.8'

services:
app:
build:
context: .
dockerfile: Dockerfile

volumes:
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

db:
image: mariadb:10.4
restart: unless-stopped
volumes:
- mariadb-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: mariadb
MYSQL_DATABASE: mariadb
MYSQL_USER: mariadb
MYSQL_PASSWORD: mariadb

# Add "forwardPorts": ["3306"] to **devcontainer.json** to forward MariaDB locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

volumes:
mariadb-data:
15 changes: 10 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# For more details, see https://containers.dev/guide/dependabot
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"xdebug.php-debug"
]
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sqltools.connections": [
{
"mysqlOptions": {
"authProtocol": "default",
"enableSsl": "Disabled"
},
"previewLimit": 50,
"server": "mysql-33158026-st-c295.f.aivencloud.com",
"port": 11500,
"driver": "MySQL",
"name": "defaultdb",
"username": "avnadmin",
"database": "clone",
"password": "AVNS_MTrsxeXJ5y6xFN_8klp"
}
]
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Try Out Development Containers: PHP
# Development Containers: PHP

1. Pham Tung Duong

2. Pham Quang Hung

[![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)

Expand Down
20 changes: 20 additions & 0 deletions defaultdb.session.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

USE QUANLYSACH;

-- Chèn 5 bản ghi cho bảng Sach
INSERT INTO Sach (MaSach, TenSach, SoLuong)
VALUES
(1, 'Sách A', 10),
(2, 'Sách B', 5),
(3, 'Sách C', 8),
(4, 'Sách D', 3),
(5, 'Sách E', 12);

-- Chèn 5 bản ghi cho bảng User
INSERT INTO User (MaUser, TenUser, MatKhau)
VALUES
(1, 'Nguyen', '123456'),
(2, 'Tran', 'abcdef'),
(3, 'Le', 'password'),
(4, 'Pham', 'qwerty'),
(5, 'Vu', 'pass123');
38 changes: 16 additions & 22 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
<?php

/*----------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*---------------------------------------------------------------------------------------*/
$uri = "mysql://avnadmin:[email protected]:11500/defaultdb?ssl-mode=REQUIRED";

function sayHello($name) {
echo "Hello $name!";
}
$fields = parse_url($uri);

?>
// build the DSN including SSL settings
$conn = "mysql:";
$conn .= "host=" . $fields["host"];
$conn .= ";port=" . $fields["port"];;
$conn .= ";dbname=defaultdb";
$conn .= ";sslmode=verify-ca;sslrootcert=ca.pem";

<html>
<head>
<title>Visual Studio Code Remote :: PHP</title>
</head>
<body>
<?php

sayHello('remote world');

phpinfo();

?>
</body>
</html>
try {
$db = new PDO($conn, $fields["user"], $fields["pass"]);

$stmt = $db->query("SELECT VERSION()");
print($stmt->fetch()[0]);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
14 changes: 14 additions & 0 deletions th1/connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";

// Tạo kết nối
$connection = new mysqli($servername, $username, $password, $dbname);

// Kiểm tra kết nối
if ($connection->connect_error) {
die("Không thể kết nối đến CSDL: " . $connection->connect_error);
}
?>
28 changes: 28 additions & 0 deletions th1/dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Trang Dashboard</title>
</head>
<body>
<h1>Trang Dashboard</h1>

<?php
session_start();

// Kiểm tra trạng thái đăng nhập
if ($_SESSION["IsLogin"] == true) {
// Hiển thị thông tin người dùng
echo "<p>Xin chào</p>";

// Hiển thị nút đăng xuất
echo '<form action="logout.php" method="post">';
echo '<input type="submit" value="Đăng xuất">';
echo '</form>';
} else {
// Chuyển hướng về trang đăng nhập nếu chưa đăng nhập
header("Location: login.htm");
exit();
}
?>
</body>
</html>
16 changes: 16 additions & 0 deletions th1/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="validateuser.php" method="POST">
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
10 changes: 10 additions & 0 deletions th1/logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
session_start();
if ($_SESSION["IsLogin"] == false) {
header("Location: login.htm");
exit(); // Dừng thực thi mã hiện tại sau khi chuyển hướng
}
$_SESSION["IsLogin"] = false;
header("Location: login.html");

?>
25 changes: 25 additions & 0 deletions th1/validateuser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
include "connect.php";

session_start();
if ($_SESSION["IsLogin"] == false) {
header("Location: login.htm");
exit(); // Dừng thực thi mã hiện tại sau khi chuyển hướng
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$password = $_POST["password"];

$sql = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$result = mysqli_query($connection, $sql);

if (mysqli_num_rows($result) == 1) {
$_SESSION["IsLogin"] = true;
header("Location: dashboard.php");
} else {
header("Location: login.html");
}
}
?>

Loading