13:59 Mon Sep  3, 2007
Cheap Hummer!

12:18 Tue Jul  4, 2006
Hummer Camp After

12:15 Tue Jul  4, 2006
Hummer Camp

Help Me Humpa
PHP and MMS Server Help
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


PHP if IP =

 
Post new topic   Reply to topic    Help Me Humpa Forum Index -> Anything PHP
View previous topic :: View next topic  
Author Message
stinkingshoe



Joined: 15 May 2006
Posts: 45

PostPosted: Fri Jun 23, 2006 6:30 pm    Post subject: PHP if IP = Reply with quote

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
View user's profile Send private message
Humpa
Site Admin


Joined: 06 Nov 2005
Posts: 10258

PostPosted: Fri Jun 23, 2006 6:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
Humpa
Site Admin


Joined: 06 Nov 2005
Posts: 10258

PostPosted: Fri Jun 23, 2006 6:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
stinkingshoe



Joined: 15 May 2006
Posts: 45

PostPosted: Sun Jun 25, 2006 12:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
Humpa
Site Admin


Joined: 06 Nov 2005
Posts: 10258

PostPosted: Sun Jun 25, 2006 12:18 pm    Post subject: Reply with quote

oops .... lol
Put quotes around them. I was thinking they were numbers, but of course they aren't quite numbers. doh

Code:
<?php
$ip_array[] = "1.1.1.1";
$ip_array[] = "2.2.2.2";
$ip_array[] = "3.3.3.3";
?>
Back to top
View user's profile Send private message
stinkingshoe



Joined: 15 May 2006
Posts: 45

PostPosted: Sun Jun 25, 2006 12:42 pm    Post subject: Reply with quote

That fixed it Very Happy
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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Help Me Humpa Forum Index -> Anything PHP All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum