-1

I am working on creating a site, but I want only people using the private company wifi "XXX" to be able to access it. That way people can't just go on the site from home. Does anyone have an idea how I can do this with php? I read about static ip addresses but it is unclear whether or not that is a viable option for this goal.

Thanks in advance for any ideas.

Joe Frambach
  • 25,568
  • 9
  • 65
  • 95
user2562568
  • 327
  • 1
  • 6
  • 15
  • I am not sure, if `HTTP` provides information about connection type, other than browser info, but a good question nevertheless, maybe better suited to [webmasters.stackexchange.com](http://webmasters.stackexchange.com) – samayo Jul 15 '13 at 23:09
  • 2
    It's something you will restrict more on the server level (IE: Apache) or on the router level. – Dany Caissy Jul 15 '13 at 23:09
  • I would use IP, depending on the company set up, but only in conjunction with a 'proper' user admin –  Jul 15 '13 at 23:10
  • I agree with Dany Caissy - you will have to setup the server or router to do this, not PHP. – DrCord Jul 15 '13 at 23:11
  • if it the site is hosted inside your company firewall/router just don't allow access from the outside. If the site is hosted outside the firewall (at a hosting company for example) then restrict access to your IP space as the firewall or server level. You can do this with PHP using the REMOTE_ADDR header, but it is much better done at the server/firewall level. – Doon Jul 15 '13 at 23:22

4 Answers4

1

What you are looking for is creating an intranet. This is like putting everything on localhost, where it can only be accessed by people sharing the same intranet. This is not really a PHP code thing, but rather how you set up your domain on your website. You basically want to set up your site on a private server owned by you that is directly on your network. If you are using Windows, you can use things like Internet Information Services (IIS) to do this.

Basically what you are doing is making your website non-existent outside of your personal (or work) network.

Lochemage
  • 3,926
  • 8
  • 11
0

In general, you would restrict this kind of stuff either with server configuration (Apache), or with router configuration. However, if you want a solution in PHP, you can use IP addresses. You could restrict access to your website to a range of IPs, this method will verify if the current IP is allowed within the range and die if it isn't :

function CheckAccess()
{
    $fromip = '127.0.0.1';

    $toip = '127.0.0.100';

    $ip = ip2long($_SERVER['REMOTE_ADDR']);

    return ($ip >= ip2long($fromip) && $ip <= ip2long($toip));
} 

if (!CheckAccess())
{
    die('Unauthorized access');
}
Dany Caissy
  • 3,118
  • 12
  • 20
  • thanks to everyone for commenting. Most people have similar answers but I can only checkmark one person qq. I will probably talk to some people to see what would be the best option out of these 3 options. Thanks! – user2562568 Jul 15 '13 at 23:40
0

As long as the web server you are using is behind a router that is not forwarding ports, that firewall should be preventing anything from the internet at large from accessing your site by default.

mh00h
  • 1,634
  • 2
  • 20
  • 44
0

You don't really need to make PHP take care of that at all. You can configure your web server (or a virtual host on the web server) to service only the local network. Bingo, you have an Intranet site.

Its even safer because if you use PHP code to control your access, you won't be able to control access to the static content such as images, documents or downloads in general.

Havenard
  • 23,249
  • 4
  • 31
  • 59