Jump to content

PHP Password validation


swamp

Recommended Posts

Hey,

 

Basically, I've written a basic php script that allows me to upload files, and then get redirected to a page that has a script to view all the files in the directory the files have been uploaded to.

 

I was wondering if anyone could help me add a bit of code that mean the upload page would require a password. Ideally this would just be a simple text field just above the submit button.

 

Cheers.

 

Kieran

Link to comment
https://forums.phpfreaks.com/topic/90664-php-password-validation/
Share on other sites

This depends on whether or not the password is universal (same for every person that uploads), or if different users can have different passwords.

 

If it's the first case, just put a password field above your submit button then, and on the page that handles your uploading, run something similar to this near the top (before any of the uploading script):

 

<?php

$pass = $_POST['password'];

if ($pass !== "your password here"){
    echo "<p>Password is incorrect!  Upload failed!</p>";
    include "upload_form.php";
    exit();
}

// run the rest of your script...

?>

 

If it's the other way, you'll have to hold the password against a list of possible values in a database or something along those lines.  Either way, the code will be about the same thing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.