[TriLUG] Restricting access within PHP

Tobias Crawley tcrawley at gmail.com
Fri Jun 24 13:48:32 EDT 2005


Mark,

Assuming you are running Apache, the following will work to prevent
users not in the 192.168.1.x subnet from seeing the page, and will
redirect them to another page instead.

if ( strpos( $_SERVER[ 'REMOTE_ADDR' ], '192.168.1.' ) === false ) {
  //redirect to another page
  header( 'location: otherpage.php' );
}

You could use regular expressions (via preg_match()) instead of
strpos(), but strpos() is faster. Not that the speed makes a
difference in this example.

Toby

On 6/24/05, Mark Freeze <mfreeze at gmail.com> wrote:
> What is the best way to restrict access to a few of my web pages to a
> certain range of ip addresses?  What I am trying to do is only allow
> employees to browse their timecard tables while at work but not from
> their homes.  All of my servers are offsite with Network Solutions and
> I do not have much, if any access to the setup and control functions
> that I would have if I were hosting this myself.
> 
> Any info on the best way to accomplish my task would be greatly appreciated.
> 
> Thanks,
> Mark.
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ  : http://trilug.org/faq/
> TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> TriLUG PGP Keyring         : http://trilug.org/~chrish/trilug.asc
> 


-- 
Tobias O. Crawley / tcrawley at gmail.com / http://tobiascrawley.net/
"Arrogance is quoting yourself." - Tobias O. Crawley
"Ignorance is quoting others." - Aaron T. Dixon



More information about the TriLUG mailing list