LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-16-2008, 04:17 AM   #1
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Slackware, Linux Mint, Maemo
Posts: 493

Rep: Reputation: 45
Limiting access to web-pages by IP-address with PHP


We need to limit access to a group of our web-pages. We use MODx CMS and it seems that the most simple way to do accomplish what we want would be to have a small PHP-script that gets executed from the HTML-templates and checks the IP-address of the user. So far all the instructions we've found from the internet deal with configuring the web-server, which in our case is not a viable option. Could anyone point us to the right direction with limiting access with php? Thanks!
 
Old 12-16-2008, 05:21 AM   #2
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
Have a look.
 
Old 12-16-2008, 06:45 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,352

Rep: Reputation: 129Reputation: 129
$_SERVER['REMOTE_ADDR'] may be of some use
 
Old 12-16-2008, 08:10 AM   #4
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Slackware, Linux Mint, Maemo
Posts: 493

Original Poster
Rep: Reputation: 45
Perfect! Here's what I ended up doing:

<?php
if (preg_match("/^xxx\.xxx\./", $_SERVER['REMOTE_ADDR'])) {
header("location: our_error_page");
exit();
}
?>

I first did it by writing refresh meta to the document with echo if the beginning of the IP-address doesn't match the regex, but that caused the page to quickly flash on screen before the refresh took place. Header is much better.

Thanks guys!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH Access Limiting By IP Address During Certain Times jordo2323 Linux - Security 7 11-20-2008 02:01 PM
can't view the .php web pages nkd Fedora 8 04-23-2008 12:57 AM
open php web pages dyool Ubuntu 3 08-19-2006 06:59 AM
ADSL Router Web configuration pages appears instead of Personal Web Server Pages procyon Linux - Networking 4 12-20-2004 05:44 PM
Can't access Linux web server web pages from LAN client jaydave Linux - Networking 4 03-16-2003 02:38 AM


All times are GMT -5. The time now is 04:51 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration