0

I have created some php pages which show data from some excel files.

I access those pages using internal IP address at the office where all PC's are connected on the same network. I access those pages from my home using external IP address.

So my question is, how do I put a password or protect my php page access from external network?

i.e. When I access php webpage from my home, it should ask for a password - how do I accomplish this?

eg: hello.php

<?php
    echo"hello world";
?>

I want to put password to this php file or if I access it using external ip address then it should ask for password.

Dmitriy Khaykin
  • 5,238
  • 1
  • 20
  • 32

2 Answers2

0

Just define your IP available in your office, then block others.

$white_list = array('8.8.8.8', '1.1.1.1');

if (! in_array($_SERVER['REMOTE_ADDR'], $white_list))
{
    header('Location: mypasswordpage.php');
}
Vincent Decaux
  • 9,857
  • 6
  • 56
  • 84
0

If you want to do this in PHP you could use:

if($_SERVER['REMOTE_ADDR'] != [YOUR OFFICE IP HERE]) {
    // die or throw an exception
}

There are also plenty of security components. See the major frameworks:

Symfony

Zend 2

You can also configure apache to knock back requests based on IP. See this SO answer

Community
  • 1
  • 1
Ben Waine
  • 1,650
  • 3
  • 21
  • 34