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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.