Jump to content

Recommended Posts

    Hello,

 

    I have a file (upload.php) that is open to all users. When a user directs their browser to the file it shows an html page with an upload feature. It has browse for file etc.

 

What I'm wanting to do is limit this file to admin only by whay of "user name is admin" or "id=12" or even ip address.

 

How would I edit a file to include this?

 

I'm using php 5 n mysql 5.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/124909-limit-file-to-admin-onlyuser-id-or-ip/
Share on other sites

create a new file and call it admin_pass.php

 

add this into the file

 

<?php 
$admin_pass = "YOURPASSWORD";

if($is_admin) {
if(!$_SESSION['admin']) {
$pass = $_POST['pass'];
	if(!$pass) {
	die('<div align="center"><form action="" method="post">Password:<Br><input type="password" name="pass"><br><input type="submit" value="Login"></form></div>');
	} else {
		if($pass == $admin_pass) {
		$_SESSION['admin'] = "somerandomstring";
		header("Location: submit.php");
		} else {
		die("Sorry Disabled : <a href \"index.php\">HOME..</a>");
		}
	}
}
}

?>

 

and in the files you wish to have a password protected page insert this at the top of them pages

 

<?php

$is_admin = true;

?>

 

make sure you admin_pass.php is included :)

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.