Secure Admin Section(Using IP)


So this will make it so that You have to be on one computer to enter your admin Section. Now If you do alot of traveling, or update your site when you're out lots. Possibly just have this protecting certain pages, And leave the Add news pages with default log in?

PHP Code
  1. $accept = array ("127", "0", "0", "1");

Put the ip that you want to be able to see the page here. Edit this.

PHP Code
  1. $remote = explode(".", $REMOTE_ADDR);
  2. $match = 1;
  3. for ($i = 0; $i < sizeof($accept); $i++) {
  4. if($remote[$i] != $accept[$i]) {
  5. $match = 0;

Now this will check to see if you IP is the same as the Specified one. Leave this.

PHP Code
  1. if ($match) {
  2. echo "Access Granted";
  3. } else {
  4. echo "Access Forbidden";
  5. }

If the IP does match. It echos "Access Granted" So you would edit that to show the admin part. If they do not match. It will show "Access Forbidden". You could leave that blank. And have this as a option at the bottom of the Admin Page to possibly edit site data? For example. Site Title or Site Slogan?

Here is the code after its all put together

PHP Code
  1. <?
  2. $accept = array ("127", "0", "0", "1"); // IP Address that is allowed to see site
  3. $remote = explode(".", $REMOTE_ADDR);
  4. $match = 1;
  5. for ($i = 0; $i < sizeof($accept); $i++) {
  6. if($remote[$i] != $accept[$i]) {
  7. $match = 0;
  8. }
  9. }
  10. if ($match) {
  11. echo "Access Granted";
  12. } else {
  13. echo "Access Forbidden";
  14. }
  15. ?>


Hope someone will be able to use this!
Stupidkid's Avatar
Author:
Views:
3,896
Rating:
Posted on Sunday 11th May 2008 at 10:38 AM
Enros
Enros's Avatar
I made this script ages ago >.<....

Also another thing.
Its used for static IP adresses u newbs.


And I think it is a very good way of securing something...

Try getting into it...
Posted on Sunday 4th May 2008 at 02:13 PM
Jackboy
Jackboy's Avatar
If your only doing it for one IP why not just do:

PHP Code
  1. $ip = '00.00.00.0';
  2. if ($_SERVER[REMOTE_ADDR] != $ip){
  3. die ("Unauthorised"); }


Sorry not tested, but why have you gone so complex for something so basic.

Fair enough you need the arrays if doing a multiple IP permission script. But i feel it would be easier to have all allowed ips in a mysql database.

@Darklight19
Some people have static IP's
Posted on Saturday 19th April 2008 at 12:50 PM
cyruswu
cyruswu's Avatar
This is seriously the worstest way of securing the admin panel.

What if? You have logmeinfree and someone controls your pc. Also, someone else can go on a different accont and broswe.

You should add a thing to check if it's an admin and do other checks.
Posted on Friday 18th April 2008 at 07:40 PM
darklight19
darklight19's Avatar
This is a bad way to secure an admin sections because IPs change.