
mobbdeep
New Members-
Posts
2 -
Joined
-
Last visited
mobbdeep's Achievements

Newbie (1/5)
0
Reputation
-
Hello, I'm looking to log the last logged in IP address from my users' accounts and their IP address used on registration. I would prefer to store the IP addresses in my database (`last_ip`) and (`registered_ip`) As far as I'm aware, the best way to store an IP address in MySQL is VARBINARY(16) for IPV6 and VARBINARY(4) for IPV4. Login.php <?php // Initialize the session session_start(); // Check if the user is already logged in, if yes then redirect to dashboard if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){ header("location: dashboard.php"); exit; } // Include ShareX config file $config = include('../i/cfg/config.php'); // Include ASE config file include_once('../ase/cfg/config.php'); // Define variables and initialize with empty values $username = $password = ""; $username_err = $password_err = $login_err = ""; // Processing form data when form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { // Check if username is empty if (empty(trim($_POST["username"]))) { $username_err = "Please enter your username."; } else { $username = trim($_POST["username"]); } // Check if password is empty if (empty(trim($_POST["password"]))) { $password_err = "Please enter your password."; } else { $password = trim($_POST["password"]); } // Validate credentials if (empty($username_err) && empty($password_err)) { // Prepare a select statement $sql = "SELECT userID, username, password FROM users WHERE username = ?"; if ($stmt = mysqli_prepare($link, $sql)) { // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_username); // Set parameters $param_username = $username; // Attempt to execute the prepared statement if (mysqli_stmt_execute($stmt)) { // Store result mysqli_stmt_store_result($stmt); // Check if username exists, if yes then verify password if (mysqli_stmt_num_rows($stmt) == 1) { // Bind result variables mysqli_stmt_bind_result($stmt, $userID, $username, $hashed_password); if (mysqli_stmt_fetch($stmt)) { if (password_verify($password, $hashed_password)) { // Password is correct, so start a new session session_start(); // Store data in session variables $_SESSION["loggedin"] = true; $_SESSION["userID"] = $userID; $_SESSION["username"] = $username; // Redirect user to welcome page header("location: dashboard.php"); } else { // Password is not valid, display a generic error message $login_err = "Invalid username or password."; } } } else { // Username doesn't exist, display a generic error message $login_err = "Invalid username or password."; } } else { echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Close connection mysqli_close($link); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <meta name="description" content="Personal image hosting powered by ShareX" /> <meta name="author" content="" /> <title>ASE - Login</title> <link rel="icon" href="assets/img/favicon.ico" type="image/x-icon"> <link href="css/styles.css" rel="stylesheet" /> <script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script> </head> <body class="bg-primary"> <div id="layoutAuthentication"> <div id="layoutAuthentication_content"> <main> <div class="container"> <div class="row justify-content-center"> <div class="col-lg-5"> <div class="card shadow-lg border-0 rounded-lg mt-5"> <div class="card-header"><h3 class="text-center font-weight-light my-4">All Seeing Eye</h3></div> <div class="card-body"> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST" class="my-login-validation" novalidate=""> <!-- Username --> <div class="form-floating mb-3"> <input id="username" type="username" class="form-control <?php echo (!empty($username_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $username; ?>" name="username" required> <label for="username">Username</label> <div class="invalid-feedback"> <?php echo $username_err; ?> </div> </div> <!-- Password --> <div class="form-floating mb-3"> <input id="password" type="password" class="form-control <?php echo (!empty($password_err)) ? 'is-invalid' : ''; ?>" name="password" required> <label for="password">Password</label> <div class="invalid-feedback"> <?php echo $password_err; ?> </div> </div> <!-- Remember Me --> <div class="form-check mb-3"> <input class="form-check-input" id="rememberMe" type="checkbox" value="lsRememberMe" required /> <label class="form-check-label" for="rememberMe">Remember Password</label> </div> <!-- Forgot Password --> <div class="d-flex align-items-center justify-content-between mt-4 mb-0"> <a class="small" href="#">Forgot Password?</a> <input type="submit" value="Login" class="btn btn-primary btn-block" onclick="lsRememberMe()"></input> </div> </form> </div> <div class="card-footer text-center py-3"> <div class="small">Need an account? <a href="register.php">Create One</a></div> </div> </div> </div> </div> </div> </main> </div> <!-- Footer --> <div id="layoutAuthentication_footer"> <footer class="py-4 bg-light mt-auto"> <div class="container-fluid px-4"> <div class="d-flex align-items-center justify-content-between small"> <div class="text-muted">Copyright © 2025 —</div> <div> <a href="#">Privacy Policy</a> · <a href="#">Terms & Conditions</a> </div> </div> </div> </footer> </div> </div> <!-- JavaScript --> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script> <script src="js/scripts.js"></script> <script src="js/rememberme.js"></script> </body> </html> Register.php <?php // Include ShareX config file include('../i/cfg/config.php'); // Include ASE config file require_once "../ase/cfg/config.php"; // Define variables and initialize with empty values $username = $email = $password = $confirm_password = ""; $username_err = $email_err = $password_err = $confirm_password_err = ""; // Processing form data when form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { // Validate username if (empty(trim($_POST["username"]))) { $username_err = "Please enter a username."; } elseif (!preg_match('/^[a-zA-Z0-9_]{3,}$/', trim($_POST["username"]))) { $username_err = "Username must contain the following:<br/><li>Minimum 3 characters long.</li><li>Only letters, numbers, and underscores."; } else { // Prepare a select statement $sql = "SELECT userID FROM users WHERE username = ?"; if ($stmt = mysqli_prepare($link, $sql)) { // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_username); // Set parameters $param_username = trim($_POST["username"]); // Attempt to execute the prepared statement if (mysqli_stmt_execute($stmt)) { /* Store result */ mysqli_stmt_store_result($stmt); if (mysqli_stmt_num_rows($stmt) == 1) { $username_err = "This username is already taken."; } else { $username = trim($_POST["username"]); } } else { echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } if (empty(trim($_POST["email"]))) { $email_err = "Please enter your email address."; } elseif (!filter_var(trim($_POST["email"]), FILTER_VALIDATE_EMAIL)) { $email_err = "Please enter a valid email address."; } else { // Prepare a select statement $sql = "SELECT userID FROM users WHERE email = ?"; if ($stmt = mysqli_prepare($link, $sql)) { // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_email); // Set parameters $param_email = trim($_POST["email"]); // Attempt to execute the prepared statement if (mysqli_stmt_execute($stmt)) { mysqli_stmt_store_result($stmt); if (mysqli_stmt_num_rows($stmt) == 1) { $email_err = "This email address is already taken."; } else { $email = trim($_POST["email"]); } } else { echo "Oops! Something went wrong. Please try again later."; } mysqli_stmt_close($stmt); } } // Validate password if (empty(trim($_POST["password"]))) { $password_err = "Please enter a password."; } elseif (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&_-])[A-Za-z\d@$!%*?&_-]{8,}$/', trim($_POST["password"]))) { $password_err = "Password must contain the following sequence:"; } else { $password = trim($_POST["password"]); } // Validate confirm password if (empty(trim($_POST["confirm_password"]))) { $confirm_password_err = "Please confirm your password."; } else { $confirm_password = trim($_POST["confirm_password"]); if (empty($password_err) && $password != $confirm_password) { $confirm_password_err = "Password did not match."; } } // Check input errors before inserting in database if (empty($username_err) && empty($email_err) && empty($password_err) && empty($confirm_password_err)) { // Prepare an insert statement $sql = "INSERT INTO users (username, email, password) VALUES (?, ?, ?)"; if ($stmt = mysqli_prepare($link, $sql)) { // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "sss", $param_username, $param_email, $param_password); // Set parameters $param_username = $username; $param_email = $email; $param_password = password_hash($password, PASSWORD_BCRYPT); // BCRYPT hashing // Attempt to execute the prepared statement if (mysqli_stmt_execute($stmt)) { // Redirect to login page header("location: index.php"); } else { echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Close connection mysqli_close($link); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <meta name="description" content="Personal image hosting powered by ShareX" /> <meta name="author" content="" /> <link rel="icon" href="assets/img/favicon.ico" type="image/x-icon"> <title>ASE - Register</title> <link href="css/styles.css" rel="stylesheet" /> <script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script> </head> <body class="bg-primary"> <div id="layoutAuthentication"> <div id="layoutAuthentication_content"> <main> <div class="container"> <div class="row justify-content-center"> <div class="col-lg-7"> <div class="card shadow-lg border-0 rounded-lg mt-5"> <div class="card-header"><h3 class="text-center font-weight-light my-4">Create Account</h3></div> <div class="card-body"> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST" class="my-login-validation" novalidate="" id="registration_form"> <!-- Username --> <div class="form-floating mb-3"> <input id="username" type="text" class="form-control <?php echo !empty($username_err) ? "is-invalid" : ""; ?>" value="<?php echo $username; ?>" name="username" required autofocus> <label for="username">Username</label> <div class="invalid-feedback"> <?php echo $username_err; ?> </div> </div> <!-- Email --> <div class="form-floating mb-3"> <input id="email" type="text" class="form-control <?php echo !empty($email_err) ? "is-invalid" : ""; ?>" value="<?php echo $email; ?>" name="email" required autofocus> <label for="email">Email Address</label> <div class="invalid-feedback"> <?php echo $email_err; ?> </div> </div> <!-- Password --> <div class="row mb-3"> <div class="col-md-6"> <div class="form-floating mb-3 mb-md-0"> <input id="password" type="password" class="form-control <?php echo !empty($password_err) ? "is-invalid" : ""; ?>" value="<?php echo $password; ?>" name="password" required data-eye oninput="validatePassword(this.value)" minlength="8"> <label for="password">Password</label> <div class="invalid-feedback"> <?php echo $password_err; ?> </div> <!-- Password Strength Meter --> <div class="form-group"> <span id="errorMessage" class="font-weight-bold text-danger" style="font-style: italic;"></span> <ul> <li id="minLength"><i class="fas fa-times text-danger"></i> Minimum 8 characters</li> <li id="uppercase"><i class="fas fa-times text-danger"></i> At least one uppercase letter</li> <li id="lowercase"><i class="fas fa-times text-danger"></i> At least one lowercase letter</li> <li id="symbol"><i class="fas fa-times text-danger"></i> At least one symbol (@$!%*?&_-)</li> </ul> </div> </div> </div> <!-- Confirm Password --> <div class="col-md-6"> <div class="form-floating mb-3 mb-md-0"> <input id="confirm_password" type="password" class="form-control <?php echo !empty($confirm_password_err) ? "is-invalid" : ""; ?>" value="<?php echo $confirm_password; ?>" name="confirm_password" required data-eye minlength="8"> <label for="confirm_password">Confirm Password</label> <div class="invalid-feedback"> <?php echo $confirm_password_err; ?> </div> </div> </div> <!-- reCaptcha --> <div class="form-group"> <div class="g-recaptcha" data-sitekey="6LdSlSAUAAAAAM3UIiPUhr9zSF8OgTT7uzQBSOcU" data-callback="verifyRecaptchaCallback" data-expired-callback="expiredRecaptchaCallback"></div> <input class="form-control d-none" data-recaptcha="true" required data-error="Please complete the Captcha"> <div class="help-block with-errors"></div> </div> </div> <!-- T&C's --> <div class="form-group"> <div class="custom-checkbox custom-control"> <input type="checkbox" name="agree" id="agree" class="custom-control-input" required=""> <label for="agree" class="custom-control-label">I agree to the <a href="#">Terms and Conditions</a></label> <div class="invalid-feedback"> You must agree with our Terms and Conditions. </div> </div> </div> <!-- Submit Form --> <div class="mt-4 mb-0"> <div class="d-grid"> <input type="submit" name="register-btn" class="btn btn-primary" value="Login"></input> </div> <!-- <button type="button" class="btn btn-danger btn-block">Registration is Closed</button></div> --> </div> </form> </div> <div class="card-footer text-center py-3"> <div class="small">Already have an account? <a href="index.php"> Sign In</a> </div> </div> </div> </div> </div> </div> </main> </div> <!-- Footer --> <div id="layoutAuthentication_footer"> <footer class="py-4 bg-light mt-auto"> <div class="container-fluid px-4"> <div class="d-flex align-items-center justify-content-between small"> <div class="text-muted">Copyright © 2025 —</div> <div> <a href="#">Privacy Policy</a> · <a href="#">Terms & Conditions</a> </div> </div> </div> </footer> </div> </div> <!-- JavaScript --> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script> <script src="js/scripts.js"></script> <script src="js/password-strength.js"></script> <script src='https://www.google.com/recaptcha/api.js' async defer></script> </body> </html>
-
Hello, I am using a simple custom ShareX image uploader script that has a little dashboard included where I can see the image info that I just screenshotted and uploaded to my host. However, I am looking to make 2 changes to the script but I'm not sure how to approach them. 1. In the screenshot, I would like to make those Delete buttons that I added functional. When I screenshot something, the image name is randomly generated so creating a button to delete a specific filename won't work. I just want to go to a row and hit Delete and it'll delete that image from my host (its designated directory). I've attached my codes below. 2. In the screenshot, the images are being sorted by the first number chronologically making them be out of order under the Image Date column. I am wanting them to be displayed by Image Date based on the most recent one taken at the top. I've attached my codes below. config.php (config script) <?php date_default_timezone_set("America/Chicago"); return array( 'secure_key' => 'my_key', 'output_url' => 'http://my_url.com/i/', 'redirect_url' => 'http://my_url.com/i/', 'allowed_ips' => array(), 'page_title' => 'my_page_title', 'heading_text' => 'my_header_text', ); upload.php (upload script) <?php $config = include('i/config.php'); $key = $config['secure_key']; $uploadhost = $config['output_url']; $redirect = $config['redirect_url']; if ($_SERVER["REQUEST_URI"] == "/robot.txt") { die("User-agent: *\nDisallow: /"); } if (isset($_POST['key'])) { if ($_POST['key'] == $key) { $parts = explode(".", $_FILES["d"]["name"]); $target = getcwd() . "/i/" . $_POST['name'] . "." . end($parts); if (move_uploaded_file($_FILES['d']['tmp_name'], $target)) { $target_parts = explode("/i/", $target); echo $uploadhost . end($target_parts); } else { echo "Sorry, there was a problem uploading your file. (Ensure your directory has 777 permissions)"; } } else { header('Location: '.$redirect); } } else { header('Location: '.$redirect); } ?> index.php (dashboard page) <?php $config = include('config.php'); ?> <html> <head> <link href="css/main.css" rel="stylesheet" type="text/css"/> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css"/> <link href="https://cdn.datatables.net/1.10.9/css/dataTables.bootstrap.min.css" rel="stylesheet" type="text/css"/> <title><?php echo $config['page_title'];?></title> </head> <body style="overflow:hidden;"> <div class="container main_container"> <h3><b><?php echo $config['heading_text'];?><br></b></h3> <?php $si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' ); $base = 1024; $bytes = disk_free_space("/"); $class = min((int)log($bytes , $base) , count($si_prefix) - 1); echo "Free Space: "; echo sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class] . ' / '; $bytes = disk_total_space("/"); $class = min((int)log($bytes , $base) , count($si_prefix) - 1); echo sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class] . '<br />'; ?> <br> <?php if(empty($config['allowed_ips']) || in_array($_SERVER['REMOTE_ADDR'], $config['allowed_ips'])){?> <?php $ignore = Array("index.php", "js", "css", ".", "..", "gallery.php", "img", "upload.php", "config.php"); $files1 = scandir("."); ?> <br> <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%"> <thead> <tr> <th>Image Name</th> <th>Image Size</th> <th>Image Type</th> <th>Image Date</th> <th>Manage Image</th> </tr> </thead> <tbody> <?php foreach($files1 as $file){ if(!in_array($file, $ignore)){?> <tr> <td><a target="_blank" href="<?php echo $config['output_url'];?><?php echo($file);?>"><?php echo($file);?></a></td> <td><?php echo filesize($file);?></td> <td><?php echo pathinfo($file, PATHINFO_EXTENSION);?></td> <td><?php echo date ("M d Y h:i A", filemtime($file))?></td> <td><button type="button" class="btn btn-danger">Delete</button></td> </tr> <?php } }?> </tbody> </table> <?php }?> </div> <script src="//code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" type="text/javascript"></script> <script src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js" type="text/javascript"></script> <script src="https://cdn.datatables.net/1.10.9/js/dataTables.bootstrap.min.js" type="text/javascript"></script> <script src="js/main.js" type="text/javascript"></script> </body> </html>