Clan Adverts

Prevent Unwanted Access To Admin.php

Description: This is a little work around to prevent any one except you from accessing admin.php
Version: 1.0
Added on: 31 January 2008
Author: Not Known
Difficulty Level: Easy
Views: 14008
Rating: 9.3 (4 Votes)
Detailed ProfileView Comments (2)

If you didn't know one of the ways a hacker will try to gain entry to your site is by gaining access to the nuke_authors table (admin users) and add his own details, then login to your admin area and create havoc !

An easy way to stop this is by only alowing your IP access to your admin.php like so,

Create a file, call it whatever you like (authority.php for example)
In that file place the following code

Code:
<?php

//This function returns True if visitor IP is allowed.
//Otherwise it returns False
function CheckAccess()
{
  //allowed IP. Change it to your static IP
  $allowedip = '127.0.0.1';

  $ip = $_SERVER['REMOTE_ADDR'];
  return ($ip == $allowedip);
}

?>


Change the ip address to your static ip address. Place the file in your root directory.

Now, open up admin.php and look for (near the top)

Code:
require_once('mainfile.php');


Below that add:

Code:
require_once('authority.php');


using the name of the file you just created.
Now look below this where you will see

Code:
if(isset($aid)) {
  if($aid AND (!isset($admin) OR empty($admin)) AND $op!='login') {
    unset($aid);
    unset($admin);
    die('Access Denied');
  }
}


After add:

Code:
//include file with CheckAccess implementation
if (!CheckAccess())
{
  //show the access denied message and exit script
  echo 'Access denied!';
  exit;
}

//access granted, normal flow
echo 'OK';


This will block access to any admin function to a single ip address, no matter what password or login is used.

If you have multiple IP's then you will need to work with the code in your new file to reflect those also.

If the new function is working, you will notice the letters "OK" in the top left of your admin pages when you access them. If you do not like that, just remove the last echo'OK' line from your edits.