This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* JsonResponse - Clean, consistent JSON API responses | |
*/ | |
class JsonResponse { | |
public static function send($status, $message, $data = [], $code = 200) { | |
http_response_code($code); | |
header('Content-Type: application/json'); | |
echo json_encode([ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Router - Lightweight PHP route handler | |
* Description: Minimal routing system for small PHP APIs or websites. | |
*/ | |
class Router { | |
private $routes = []; | |
public function get($path, $callback) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Logger - Simple file logger for PHP | |
* Description: Logs messages or errors into a daily log file. | |
*/ | |
class Logger { | |
private static $logDir = __DIR__ . '/logs/'; | |
public static function write($message, $type = 'INFO') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* EnvLoader - Simple .env file loader for PHP | |
* Author: Victor E. | |
* Description: Loads environment variables from a .env file into $_ENV | |
*/ | |
class EnvLoader { | |
public static function load($filePath = '.env') { | |
if (!file_exists($filePath)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function generateTransactionID($prefix = 'TXN') { | |
$time = microtime(true); | |
$random = bin2hex(random_bytes(4)); | |
return strtoupper($prefix . '-' . dechex($time) . '-' . $random); | |
} | |
// This file is intended to generate a transaction ID. | |
// Ensure that the logic for generating the transaction ID is implemented within this file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = "https://api.example.com/data"; | |
$data = ["username" => "Victor", "token" => "123456"]; | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); | |
$response = curl_exec($ch); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
$target = "uploads/" . basename($_FILES["file"]["name"]); | |
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target)) { | |
echo "File uploaded: " . htmlspecialchars($_FILES["file"]["name"]); | |
} else { | |
echo "Upload failed."; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function generateToken($userId) { | |
$secret = 'my_secret_key'; | |
$payload = [ | |
'user_id' => $userId, | |
'iat' => time(), | |
'exp' => time() + (60 * 60) // 1 hour | |
]; | |
return base64_encode(json_encode($payload)) . '.' . md5($secret); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$host = 'localhost'; | |
$db = 'my_database'; | |
$user = 'root'; | |
$pass = ''; | |
$charset = 'utf8mb4'; | |
$dsn = "mysql:host=$host;dbname=$db;charset=$charset"; | |
try { |