Commit a18d2c1d authored by muhammad-ameen356's avatar muhammad-ameen356

PHP

parents
img
dashboard
webalizer
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bitnami: Open Source. Simplified</title>
<link href="bitnami.css" media="all" rel="Stylesheet" type="text/css" />
<link href="/dashboard/stylesheets/all.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="contain-to-grid">
<nav class="top-bar" data-topbar>
<ul class="title-area">
<li class="name">
<h1><a href="/dashboard/index.html">Apache Friends</a></h1>
</li>
<li class="toggle-topbar menu-icon">
<a href="#">
<span>Menu</span>
</a>
</li>
</ul>
<section class="top-bar-section">
<!-- Right Nav Section -->
<ul class="right">
<li class="active"><a href="/applications.html">Applications</a></li>
<li class=""><a href="/dashboard/faq.html">FAQs</a></li>
<li class=""><a href="/dashboard/howto.html">HOW-TO Guides</a></li>
<li class=""><a target="_blank" href="/dashboard/phpinfo.php">PHPInfo</a></li>
<li class=""><a href="/phpmyadmin/">phpMyAdmin</a></li>
</ul>
</section>
</nav>
</div>
<div id="wrapper">
<div class="hero">
<div class="row">
<div class="large-12 columns">
<p>Apache Friends and Bitnami are cooperating to make dozens of open source applications available on XAMPP, for free. Bitnami-packaged applications include Wordpress, Drupal, Joomla! and dozens of others and can be deployed with one-click installers. Visit the <a href="https://bitnami.com/xampp?utm_source=bitnami&utm_medium=installer&utm_campaign=XAMPP%2BModule" target="_blank">Bitnami XAMPP page</a> for details on the currently available apps.</p><br/>
<p>Check out our <a href="https://www.apachefriends.org/bitnami_for_xampp.html" target="_blank" >Bitnami for XAMPP Start Guide</a> for more information about the applications installed.</p>
</div>
</div>
</div>
<div id="lowerContainer" class="row">
<div id="content" class="large-12 columns">
<!-- @@BITNAMI_MODULE_PLACEHOLDER@@ -->
</div>
</div>
</div>
<footer>
<div class="row">
<div class="large-12 columns">
<div class="row">
<div class="large-8 columns">
<ul class="social">
<li class="twitter"><a href="https://twitter.com/apachefriends">Follow us on Twitter</a></li>
<li class="facebook"><a href="https://www.facebook.com/we.are.xampp">Like us on Facebook</a></li>
<li class="google"><a href="https://plus.google.com/+xampp/posts">Add us to your G+ Circles</a></li>
</ul>
<ul class="inline-list">
<li><a href="https://www.apachefriends.org/blog.html">Blog</a></li>
<li><a href="https://www.apachefriends.org/privacy_policy.html">Privacy Policy</a></li>
<li>
<a target="_blank" href="http://www.fastly.com/"> CDN provided by
<img width="48" data-2x="/dashboard/images/fastly-logo@2x.png" src="/dashboard/images/fastly-logo.png" />
</a>
</li>
</ul>
</div>
<div class="large-4 columns">
<p class="text-right">Copyright (c) 2015, Apache Friends</p>
</div>
</div>
</div>
</div>
</footer>
</body>
</html>
.module_top, .module_bottom{
visibility: hidden;
}
table {
border: 0px !important;
}
.module_content img{
min-width: 70px;
}
.module_content h2{
font-size: 30px;
}
<?php
if (isset($_GET['file'])) {
$fileName = $_GET['file'];
$filePath = "uploads/" . $fileName;
if (file_exists($filePath)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
readfile($filePath);
} else {
echo "File not found.";
}
} else {
echo "Invalid request.";
}
?>
favicon.ico

30.2 KB

<?php
$uploadDir = "uploads/";
$files = scandir($uploadDir);
echo "<pre>";
print_r($files);
echo "</pre>";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Upload Form</title>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('uploadForm').addEventListener('submit', function(e) {
e.preventDefault();
var formData = new FormData(this);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'upload.php', true);
xhr.onload = function() {
if (xhr.status === 200) {
alert(xhr.responseText); // Display any response from the server
// You can also update the page or perform additional actions here
} else {
alert('Error uploading file.');
}
};
xhr.send(formData);
});
});
</script>
</head>
<body>
<form id="uploadForm" enctype="multipart/form-data">
<label for="file">Choose a file:</label>
<input type="file" name="file" id="file" required>
<button type="submit">Upload</button>
</form>
<br>
<a href="file_listing.php">File Listing</a>
</body>
</html>
<?php
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
$uri = 'https://';
} else {
$uri = 'http://';
}
$uri .= $_SERVER['HTTP_HOST'];
header('Location: '.$uri.'/dashboard/');
exit;
?>
Something is wrong with the XAMPP installation :-(
<?php
if (isset($_GET['file'])) {
$fileName = $_GET['file'];
$filePath = "uploads/" . $fileName;
if (file_exists($filePath)) {
$fileContent = file_get_contents($filePath);
echo "<h2>File Content: $fileName</h2>";
echo "<pre>$fileContent</pre>";
} else {
echo "File not found.";
}
} else {
echo "Invalid request.";
}
?>
<?php
$itemID_1 = 101;
$itemName_1 = "Laptop";
$itemPrice_1 = 1200;
$itemQuantity_1 = 10;
$itemAvailability_1 = true;
$itemID_2 = 102;
$itemName_2 = "Printer";
$itemPrice_2 = 200;
$itemQuantity_2 = 5;
$itemAvailability_2 = false;
$itemID_3 = 103;
$itemName_3 = "Mouse";
$itemPrice_3 = 20;
$itemQuantity_3 = 5;
$itemAvailability_3 = true;
$inventory_items = [
["ID" => $itemID_1, "Name" => $itemName_1, "Price" => $itemPrice_1, "Quantity" => $itemQuantity_1, "Availability" => $itemAvailability_1],
["ID" => $itemID_2, "Name" => $itemName_2, "Price" => $itemPrice_2, "Quantity" => $itemQuantity_2, "Availability" => $itemAvailability_2],
["ID" => $itemID_3, "Name" => $itemName_3, "Price" => $itemPrice_3, "Quantity" => $itemQuantity_3, "Availability" => $itemAvailability_3]
];
?>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Registration</title>
</head>
<body>
<h2>User Registration Form</h2>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<input type="hidden" name="csrf_token" value="<?php echo generate_csrf_token(); ?>">
<label for="username">Username:</label>
<input type="text" name="username" >
<label for="email">Email:</label>
<input type="email" name="email" >
<label for="password">Password:</label>
<input type="password" name="password" >
<label for="confirm_password">Confirm Password:</label>
<input type="password" name="confirm_password" >
<button type="submit">Register</button>
</form>
</body>
</html>
<?php
$users = [];
function generate_csrf_token() {
return bin2hex(random_bytes(32));
}
function validate_csrf_token($token) {
return isset($_SESSION['csrf_token']) && hash_equals($_SESSION['csrf_token'], $token);
}
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$csrf_token = $_POST['csrf_token'];
if (!validate_csrf_token($csrf_token)) {
die("CSRF token validation failed.");
}
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
if (empty($username) || empty($email) || empty($password) || empty($confirm_password) || !filter_var($email, FILTER_VALIDATE_EMAIL) || $password !== $confirm_password) {
die("Validation failed. Please fill in all required fields, use a valid email, and ensure passwords match.");
}
if (strlen($password) < 8 || !preg_match("/[A-Z]+/", $password) || !preg_match("/[a-z]+/", $password) || !preg_match("/[0-9]+/", $password)) {
die("Password should be at least 8 characters long and include uppercase, lowercase, and numeric characters.");
}
$hashed_password = password_hash($password, PASSWORD_BCRYPT);
$users[$email] = [
'username' => $username,
'email' => $email,
'hashed_password' => $hashed_password,
];
echo "Registration successful!";
} else {
echo "Access denied. Please submit the form.";
}
?>
<?php
$uploadDir = "uploads/";
// File Upload Handling
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$allowedExtensions = array("txt", "csv", "pdf", "jpg", "jpeg", "png");
$maxFileSize = 5242880; // 5 MB
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
if (!in_array(strtolower($fileExtension), $allowedExtensions)) {
echo "Error: Unsupported file type.";
exit();
}
if ($fileSize > $maxFileSize) {
echo "Error: File size exceeds the limit.";
exit();
}
$destination = $uploadDir . $fileName;
move_uploaded_file($fileTmpName, $destination);
echo "File uploaded successfully!";
}
}
$files = array_diff(scandir($uploadDir), array('..', '.'));
if (isset($_GET['read'])) {
$selectedFile = $_GET['read'];
$filePath = $uploadDir . $selectedFile;
if (file_exists($filePath)) {
$fileContent = file_get_contents($filePath);
echo "<h2>File Content: $selectedFile</h2>";
echo "<pre>$fileContent</pre>";
} else {
echo "File not found.";
}
}
// Write to CSV File
if (isset($_POST['content']) && isset($_POST['write'])) {
$content = $_POST['content'];
$csvContent = explode("\n", $content);
$csvFilePath = $uploadDir . "example.csv";
file_put_contents($csvFilePath, implode("\n", $csvContent));
echo "CSV file written successfully!";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Management</title>
</head>
<body>
<h2>File Upload</h2>
<form action="" method="post" enctype="multipart/form-data">
<label for="file">Choose a file:</label>
<input type="file" name="file" id="file" required>
<button type="submit" name="submit">Upload</button>
</form>
<h2>File Listing</h2>
<ul>
<?php
foreach ($files as $file) {
echo "<li><a href='?read=$file'>$file</a> - <a href='?download=$file'>Download</a></li>";
}
?>
</ul>
<h2>Read and Write Files</h2>
<?php
if (isset($_GET['read'])) {
echo "<form action='' method='post'>";
echo "<textarea name='content' rows='10' cols='30'>$fileContent</textarea><br>";
echo "<button type='submit' name='write'>Write to CSV</button>";
echo "</form>";
}
?>
<h2>File Download</h2>
<?php
if (isset($_GET['download'])) {
$fileToDownload = $_GET['download'];
$downloadLink = $uploadDir . $fileToDownload;
if (file_exists($downloadLink)) {
echo "<p><a href='$downloadLink' download>Download $fileToDownload</a></p>";
} else {
echo "File not found.";
}
}
?>
</body>
</html>
<?php
$serverName = "127.0.0.1";
$username = "root";
$password = "12345";
$database = "task_management";
$conn = new mysqli($serverName, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE IF NOT EXISTS $database";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully<br>";
} else {
echo "Error creating database: " . $conn->error;
}
// Select the database
$conn->select_db($database);
// Create table
$sql = "CREATE TABLE IF NOT EXISTS tasks (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
if ($conn->query($sql) === TRUE) {
echo "Table tasks created successfully<br>";
} else {
echo "Error creating table: " . $conn->error;
}
// Handle task creation form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$title = $_POST['title'];
$description = $_POST['description'];
$sql = "INSERT INTO tasks (title, description) VALUES ('$title', '$description')";
if ($conn->query($sql) === TRUE) {
echo "New task created successfully<br>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
// Handle task update form submission
if (isset($_POST['update'])) {
$id = $_POST['task_id'];
$title = $_POST['title'];
$description = $_POST['description'];
$sql = "UPDATE tasks SET title='$title', description='$description' WHERE id=$id";
if ($conn->query($sql) === TRUE) {
echo "Task updated successfully<br>";
} else {
echo "Error updating task: " . $conn->error;
}
}
// Handle task deletion
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$sql = "DELETE FROM tasks WHERE id=$id";
if ($conn->query($sql) === TRUE) {
echo "Task deleted successfully<br>";
} else {
echo "Error deleting task: " . $conn->error;
}
}
// Display task listing
$sql = "SELECT * FROM tasks";
$result = $conn->query($sql);
echo "<h2>Tasks</h2>";
if ($result->num_rows > 0) {
echo "<ul>";
while ($row = $result->fetch_assoc()) {
echo "<li>" . $row["title"] . " - " . $row["description"] . " - Created at: " . $row["created_at"] . " <a href='?delete=" . $row["id"] . "'>Delete</a> <a href='update.php?id=" . $row["id"] . "'>Update</a></li>";
}
echo "</ul>";
} else {
echo "No tasks found";
}
// Close connection
$conn->close();
?>
<!-- Task Creation Form -->
<h2>Add New Task</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label>Title:</label><br>
<input type="text" name="title"><br>
<label>Description:</label><br>
<textarea name="description"></textarea><br>
<input type="submit" value="Submit">
</form>
<?php
// Abstract class representing a purchasable item
abstract class Purchasable {
abstract public function calculateTotalPrice();
}
// Trait for discountable items
trait Discountable {
protected $discount = 0;
public function applyDiscount($amount) {
$this->discount = $amount;
}
public function getDiscount() {
return $this->discount;
}
}
// Base class representing a generic product
class Product extends Purchasable {
protected $id;
protected $name;
protected $price;
protected $quantity;
public function __construct($id, $name, $price, $quantity) {
$this->id = $id;
$this->name = $name;
$this->price = $price;
$this->quantity = $quantity;
}
public function getId() {
return $this->id;
}
public function getName() {
return $this->name;
}
public function getPrice() {
return $this->price;
}
public function getQuantity() {
return $this->quantity;
}
public function calculateTotalPrice() {
return $this->price * $this->quantity;
}
}
// Derived class for electronic products
class ElectronicProduct extends Product {
protected $brand;
protected $warranty;
public function __construct($id, $name, $price, $quantity, $brand, $warranty) {
parent::__construct($id, $name, $price, $quantity);
$this->brand = $brand;
$this->warranty = $warranty;
}
public function getBrand() {
return $this->brand;
}
public function getWarranty() {
return $this->warranty;
}
public function displayInfo() {
echo "Electronic Product: {$this->getName()} - {$this->getBrand()} - {$this->getPrice()} - {$this->getQuantity()} - {$this->getWarranty()}";
}
}
// Derived class for clothing products
class ClothingProduct extends Product {
protected $size;
protected $material;
public function __construct($id, $name, $price, $quantity, $size, $material) {
parent::__construct($id, $name, $price, $quantity);
$this->size = $size;
$this->material = $material;
}
public function getSize() {
return $this->size;
}
public function getMaterial() {
return $this->material;
}
public function displayInfo() {
echo "Clothing Product: {$this->getName()} - {$this->getSize()} - {$this->getMaterial()} - {$this->getPrice()} - {$this->getQuantity()}";
}
}
// Example usage
$electronicProduct = new ElectronicProduct('E001', 'Laptop', 999, 2, 'Dell', '1 year');
$clothingProduct = new ClothingProduct('C001', 'T-Shirt', 20, 5, 'M', 'Cotton');
$electronicProduct->displayInfo();
echo "\n";
$clothingProduct->displayInfo();
echo "\n";
// Applying discount
$electronicProduct->applyDiscount(50);
echo "Discount applied to electronic product: {$electronicProduct->getDiscount()}";
<?php
session_start();
$serverName = "127.0.0.1";
$username = "root";
$password = "12345";
$database = "task_management";
$conn = new mysqli($serverName, $username, $password, $database);
// Database connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// User Registration
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['register'])) {
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
// Validate input (e.g., check if email is valid, username doesn't already exist, etc.)
// Hash the password
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Store user information securely in the database
$sql = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$hashed_password')";
if ($conn->query($sql) === TRUE) {
echo "User registered successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
// User Login
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// Retrieve hashed password from the database
$sql = "SELECT * FROM users WHERE username='$username'";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
if (password_verify($password, $row['password'])) {
$_SESSION['username'] = $username;
header("Location: dashboard.php");
exit();
} else {
echo "Incorrect password";
}
} else {
echo "User not found";
}
}
// Logout
if (isset($_GET['logout'])) {
session_destroy();
header("Location: login.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>User Registration & Login</title>
</head>
<body>
<h2>User Registration</h2>
<form action="" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br>
<input type="submit" value="Register" name="register">
</form>
<h2>User Login</h2>
<form action="" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br>
<input type="submit" value="Login" name="login">
</form>
</body>
</html>
<?php
$serverName = "127.0.0.1";
$username = "root";
$password = "12345";
$database = "task_management";
// Create connection
$conn = new mysqli($serverName, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch task details
$id = $_GET['id'];
$sql = "SELECT * FROM tasks WHERE id=$id";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
// Close connection
$conn->close();
?>
<!-- Task Update Form -->
<h2>Update Task</h2>
<form method="post" action="task5.php">
<input type="hidden" name="task_id" value="<?php echo $row['id']; ?>">
<label>Title:</label><br>
<input type="text" name="title" value="<?php echo $row['title']; ?>"><br>
<label>Description:</label><br>
<textarea name="description"><?php echo $row['description']; ?></textarea><br>
<input type="submit" name="update" value="Update">
</form>
<?php
$uploadDir = "uploads/";
if (isset($_POST['submit'])) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
if ($fileError === 0) {
$destination = $uploadDir . $fileName;
move_uploaded_file($fileTmpName, $destination);
header("Location: index.html");
} else {
echo "Error uploading file.";
}
}
?>
<?php
$content = "Name, Age, Email\nJohn Doe, 25, john@example.com\nJane Smith, 30, jane@example.com";
$file = fopen("uploads/example.csv", "w");
fwrite($file, $content);
fclose($file);
echo "CSV file written successfully.";
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment