Quickpaste.it
Create Paste
Top Pastes
Recent Pastes
Settings
Account
Untitled Paste
Created By
Anonymous
Expires never
Raw
Download
0
<?php require 'server/connect.php'; require 'includes/functions.php'; session_start(); ini_set('display_errors', 1); error_reporting(E_ALL); if (isset($_SESSION['loggedin'])) { $userLoggedIn = isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === 1; $pasteBy = !$userLoggedIn ? $_SESSION['id'] : $_SESSION['id']; } $userLoggedIn = isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true; $pasteBy = $userLoggedIn ? $_SESSION['username'] : 'Anonymous'; $pasteUserId = $userLoggedIn ? $_SESSION['id'] : 0; if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST['message'])) { $original_message = trim($_POST['message']); $visibility = ($_POST['visibility'] == 'public') ? 1 : 0; $password = !empty($_POST['password']) ? hashPassword($_POST['password']) : NULL; $expiry = calculateExpiry($_POST['expiry']); $title = trim($_POST['title']); $encrypted_message = encryptMessage($original_message, $secret_key, $secret_iv, $encrypt_method); $uniqueId = generateUniqueId(5); $stmt = $conn->prepare("INSERT INTO paste (unique_id, message, visibility, paste_password, paste_expiry, paste_title, paste_by, paste_user_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); if (!$stmt) { echo "Prepare failed: (" . $conn->errno . ") " . $conn->error; } else { $stmt->bind_param("ssissssi", $uniqueId, $encrypted_message, $visibility, $password, $expiry, $title, $pasteBy, $pasteUserId); if (!$stmt->execute()) { echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error; } else { header('Location: ' . 'view.php?unique_id=' . $uniqueId); exit; } $stmt->close(); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Create New Paste</title> <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"> <style> .dark-bg { background-color: #121212; /* Dark background */ background-color: #121212; } .text-area-bg { background-color: #333333; /* Darker textarea background */ color: #ffffff; /* White text for better contrast */ background-color: #333333; color: #ffffff; } .full-width { width: 100%; /* Ensure button is full-width */ width: 100%; } @media (max-width: 768px) { .responsive-grid { grid-template-columns: repeat(1, minmax(0, 1fr)); /* Stack elements in a single column on smaller screens */ grid-template-columns: repeat(1, minmax(0, 1fr)); } } </style> </head> <?php require('includes/navbar.php') ?> <body class="dark-bg text-white"> <?php require('includes/ads.php') ?> <div class="flex justify-center items-center min-h-screen px-4"> <div class="w-full max-w-4xl"> <h2 class="text-center text-xl font-bold mb-6">Create New Paste</h2> <form method="post" action="" class="space-y-6"> <div> <label for="title" class="block text-sm font-bold mb-2">Title</label> <input type="text" name="title" id="title" placeholder="Paste Title" class="text-area-bg shadow appearance-none border rounded w-full py-2 px-3 leading-tight focus:outline-none focus:shadow-outline"> </div> <div class="grid md:grid-cols-3 gap-4 responsive-grid"> <div> <label for="visibility" class="block text-sm font-bold mb-2">Visibility</label> <select name="visibility" id="visibility" class="text-area-bg shadow border rounded w-full py-2 px-3 leading-tight focus:outline-none focus:shadow-outline"> <option value="public">Public</option> <option value="private">Private</option> </select> </div> <div> <label for="password" class="block text-sm font-bold mb-2">Password (Optional)</label> <input type="password" name="password" id="password" placeholder="Password" class="text-area-bg shadow appearance-none border rounded w-full py-2 px-3 leading-tight focus:outline-none focus:shadow-outline"> </div> <div> <label for="expiry" class="block text-sm font-bold mb-2">Expiry Time</label> <select name="expiry" id="expiry" class="text-area-bg shadow border rounded w-full py-2 px-3 leading-tight focus:outline-none focus:shadow-outline"> <option value="">No Expiry</option> <option value="1_hour">1 Hour</option> <option value="1_day">1 Day</option> <option value="1_week">1 Week</option> <option value="1_month">1 Month</option> <option value="1_year">1 Year</option> <option value="10_years">10 Years</option> </select> </div> </div> <div> <label for="message" class="block text-sm font-bold mb-2">Message</label> <textarea name="message" id="message" rows="10" placeholder="Enter your message here" class="text-area-bg shadow appearance-none border rounded w-full py-2 px-3 leading-tight focus:outline-none focus:shadow-outline"></textarea> </div> <button type="submit" class="full-width bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline mt-4">Paste</button> </form> </div> </div> </body> <?php require('includes/footer.php') ?> </html> 2 changes: 0 additions & 2 deletions2 server/connect.php @@ -1,13 +1,11 @@ <?php error_reporting(E_ALL); // configuration $secret_key = "5fb6e0d1b9ad8782ddc30c914d47468586926907b3d1e4517e0d1d350af2efe3"; $secret_iv = "48e5e4240ad0e2f6558d2faa0de4b180"; $encrypt_method = "AES-256-CBC"; //db connection $servername = "localhost"; $username = "root"; $password = ""; $dbname = "pastebin"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } ?> 1 change: 0 additions & 1 deletion1 top.php @@ -3,7 +3,6 @@ require 'includes/functions.php'; $pastes = []; // The SQL query now orders the pastes by views in descending order $stmt = $conn->prepare(" SELECT p.unique_id, p.paste_title, p.created_at, p.likes, p.dislikes, p.views, CASE WHEN p.paste_by = 0 THEN 'Anonymous' ELSE u.username END AS username FROM paste p LEFT JOIN users u ON p.paste_by = u.id WHERE p.visibility = 1 ORDER BY p.views DESC, p.created_at DESC LIMIT 10 "); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $pastes[] = $row; } } $stmt->close(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Top Pastes</title> <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"> </head> <?php require('includes/navbar.php'); ?> <body class="bg-black text-white" style="background-color: #121213 !important;"> <?php require('includes/ads.php') ?> <div class="flex flex-col items-center justify-center min-h-screen"> <div class="bg-gray-800 p-6 rounded-lg shadow-lg" style="width: 90%; max-width: 1200px; margin: auto; background-color: #212123 !important;"> <h2 class="text-2xl font-bold mb-6 text-center">Top Pastes</h2> <div class="overflow-auto"> <table class="w-full text-white"> <thead class="text-pink-600"> <tr> <th class="text-left py-2 px-3">Title</th> <th class="text-left py-2 px-3">Pasted By</th> <th class="text-left py-2 px-3">Likes</th> <th class="text-left py-2 px-3">Dislikes</th> <th class="text-left py-2 px-3">Views</th> <th class="text-left py-2 px-3">Created Time</th> </tr> </thead> <tbody class="border-t border-pink-600"> <?php foreach ($pastes as $paste): ?> <tr class="hover:bg-gray-700 cursor-pointer" onclick="window.location='view.php?unique_id=<?php echo htmlspecialchars($paste['unique_id']); ?>'"> <td class="py-2 px-3"><?php echo htmlspecialchars($paste['paste_title']); ?></td> <td class="py-2 px-3"><?php echo htmlspecialchars($paste['username']); ?></td> <td class="py-2 px-3"><?php echo htmlspecialchars($paste['likes']); ?></td> <td class="py-2 px-3"><?php echo htmlspecialchars($paste['dislikes']); ?></td> <td class="py-2 px-3"><?php echo htmlspecialchars($paste['views']); ?></td> <td class="py-2 px-3 text-gray-400 text-sm"><?php echo time_elapsed_string($paste['created_at']); ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <?php require('includes/footer.php'); ?> </body> </html>