When it comes to PHP website backend management, the code usually involves tasks such as user authentication, permission control, data management, and more. Below is a simple example:
<?php session_start(); $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Establish a connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } if (isset($_POST['submit'])) { $user = $_POST['username']; $pass = $_POST['password']; $sql = "SELECT * FROM users WHERE username='$user' AND password='$pass'"; $result = $conn->query($sql); if ($result->num_rows > 0) { $_SESSION['username'] = $user; header('Location: dashboard.php'); } else { echo "Username or password is incorrect"; } } ?>
<?php session_start(); if (!isset($_SESSION['username'])) { header('Location: login.php'); } ?>Dashboard Welcome, <?php echo $_SESSION['username']; ?>!
<?php session_start(); if (!isset($_SESSION['username'])) { header('Location: login.php'); } $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Establish a connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Query data $sql = "SELECT id, name, email FROM users"; $result = $conn->query($sql); if ($result->num_rows > 0) { // Output data while ($row = $result->fetch_assoc()) { echo "id: " . $row["id"] . " Name: " . $row["name"] . " Email: " . $row["email"] . "
"; } } else { echo "0 results"; } $conn->close(); ?>
In practice, the code provided above is for reference only and should be adjusted according to specific requirements.
1. View user list
2. Add new user
3. Edit user information
4. Delete user
5. View logs
Below is an example of HTML and PHP code presenting these functionalities:
Make sure to follow best practices when deploying any web-based application, especially when handling user data and database interactions. The provided code examples have omitted database connection and query execution for brevity, as these typically involve more configuration and security considerations. In a production environment, use prepared statements to prevent SQL injection and validate/clean user input.
Thank you for reading and feel free to leave comments, follow for more updates, like the content, and thank you for your attention!