| View previous topic :: View next topic |
| Author |
Message |
stinkingshoe
Joined: 15 May 2006 Posts: 45
|
Posted: Fri Jun 23, 2006 6:30 pm Post subject: PHP if IP = |
|
|
I'm assuming something like this would be incredibly easy... for those that know how to program (ie: you lol)
This is the pseudo code.. hopefully you can help me make it php...
in my index.php..
if users ip == any ips stored in server_root/ip.txt then
require banned.php
else
require unbanned.php
end if
Basically, I don't want a huge "BANNED" message to pop up... I just want to have index.php grab the code out of another page depending on what your IP address is (ie: if I log into my website at work, there will be different links then when I log into my site anywhere else)
By using PHP, if the user goes to view source, they will only see the urls and code that they are meant to see... do you understand? |
|
| Back to top |
|
 |
Humpa Site Admin

Joined: 06 Nov 2005 Posts: 10258
|
Posted: Fri Jun 23, 2006 6:42 pm Post subject: |
|
|
Make a file called ip.php instead of ip.txt
Then do something like this:
| Code: |
<?php
$ip_array[] = 1.1.1.1;
$ip_array[] = 2.2.2.2;
$ip_array[] = 3.3.3.3;
?> |
Just put in as many lines of ip's as you want.
Then in your index.php, do this:
| Code: |
<?php
$ip = $_SERVER[REMOTE_ADDR];
if(in_array($ip, $ip_array)) {
include("banned.php");
}else {
include("unbanned.php");
}
?> |
|
|
| Back to top |
|
 |
Humpa Site Admin

Joined: 06 Nov 2005 Posts: 10258
|
Posted: Fri Jun 23, 2006 6:53 pm Post subject: |
|
|
I forgot a line in the index.php:
| Code: |
<?php
$ip = $_SERVER[REMOTE_ADDR];
include("ip.php");
if(in_array($ip, $ip_array)) {
include("banned.php");
}else {
include("unbanned.php");
}
?> |
|
|
| Back to top |
|
 |
stinkingshoe
Joined: 15 May 2006 Posts: 45
|
Posted: Sun Jun 25, 2006 12:15 pm Post subject: |
|
|
I get an error:
Parse error: parse error, unexpected T_DNUMBER in /home/content/s/u/t/username/html/ip.php on line 2 |
|
| Back to top |
|
 |
Humpa Site Admin

Joined: 06 Nov 2005 Posts: 10258
|
Posted: Sun Jun 25, 2006 12:18 pm Post subject: |
|
|
oops .... lol
Put quotes around them. I was thinking they were numbers, but of course they aren't quite numbers.
| Code: |
<?php
$ip_array[] = "1.1.1.1";
$ip_array[] = "2.2.2.2";
$ip_array[] = "3.3.3.3";
?> |
|
|
| Back to top |
|
 |
stinkingshoe
Joined: 15 May 2006 Posts: 45
|
Posted: Sun Jun 25, 2006 12:42 pm Post subject: |
|
|
That fixed it
I was tryin' a couple of different things.. I think I may have gotten to that solution eventually, you just beat me to it, haha
Thanks again |
|
| Back to top |
|
 |
|