Suggested fixes are applied

This commit is contained in:
SovereigntyIsNotFreedom 2025-04-13 19:05:59 +01:00
parent 4837034ec3
commit e21455540e
4 changed files with 39 additions and 34 deletions

View file

@ -1,18 +1,3 @@
<?php
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
}
closedir($dh);
}
}
?>
<!DOCTYPE html>
<html>
<head>

View file

@ -1,4 +1,8 @@
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
session_start();
if (isset($_POST['submit'])){
@ -6,6 +10,8 @@ if (isset($_POST['submit'])){
$link = htmlspecialchars($_POST['link']);
$name = htmlspecialchars($_POST['name']);
$description = htmlspecialchars($_POST['description']);
$sensitive = htmlspecialchars($_POST['sensitive']);
$category = htmlspecialchars($_POST['category']);
$captcha = htmlspecialchars($_POST['captcha']);
// Captcha Auth check
if ($captcha != htmlspecialchars($_SESSION['secure'])){
@ -14,18 +20,16 @@ if (isset($_POST['submit'])){
if (empty($link) or empty($name) or empty($description)){
echo "All of the fields must not be empty";
}else{
// Clearing unusual characters in all the fields
$clear_link = str_replace(['@','*','(',') ',';','#'],'',$link);
$clear_name = str_replace(['@','.',',','(',')','#',';'],'',$name);
$clear_description = str_replace(['@',';'], '', $description);
if (strlen($link) > 512 or strlen($name) > 64 or strlen($description) > 256 or strlen($sensitive) > 1 or strlen($category) > 64){
echo "Don't excede the limit";
}else{
// Open the file once before the loop
$file = fopen("../submissions/submission.csv", "a");
if ($file !== false) {
// Create an array with the inputs to write as a single row
$row = [$clear_link, $clear_name,$clear_description];
$row = [$link, $name,$description,$category,$sensitive];
// Write the row to the CSV file
fputcsv($file, $row, ',', '"');
@ -37,6 +41,7 @@ if (isset($_POST['submit'])){
errorlog("Error opening the file.");
}
header("Location: index.php");
}
}
}
}
@ -66,6 +71,14 @@ if (isset($_POST['submit'])){
<html>
<?php include("header.php");?>
<div class="width-class">
<center>
<h1>Character Limits</h1>
<p>Link should be 354</p>
<p>Name should be 64</p>
<p>Description should be 256</p>
<p>Category should be 64</p>
<p>Sensitive should be 1</p>
</center>
<form action="submit.php" method="POST">
<label style="color:white">Link</label>
<input required class="input-class" type="text" name="link" placeholder="http://link.com/onion">
@ -73,6 +86,10 @@ if (isset($_POST['submit'])){
<input required class="input-class" type="text" name="name">
<label style="color:white">Description</label>
<input required class="input-class" type="text" name="description">
<label style="color:white">Category</label>
<input required class="input-class" type="text" name="category">
<label style="color:white">Sensitive</label>
<input required class="input-class" type="text" name="sensitive" placeholder="y/n">
<label style="color:white">Captcha</label>
<div>
<img src="generate.php">