Be a Supporter!

Php: Managing IP addresses

  • 2,525 Views
  • 12 Replies
New Topic Respond to this Topic
WoogieNoogie
WoogieNoogie
  • Member since: Jun. 26, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to Php: Managing IP addresses 2006-03-16 18:47:11 Reply

I like it! Nice and simple.

One thing I would change...I would think it to be more efficient:

if($ipaddress=="xxx.xxx.xxx") {
}
if($ipaddress=="xxx.xxx.xxx") {
}

I personally would change those to elseif statements. Such as...

if ($ipaddress == "xxx.xxx.xxx") {
} elseif ($ipaddress == "xxx.xxx.xxx") {
} else {
}

It doesn't make much of a difference, I belive, but I like seeing it all through one statement.

All in all, I like the tutorial :)

DashDingo
DashDingo
  • Member since: Jun. 25, 2004
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to Php: Managing IP addresses 2006-03-16 20:50:00 Reply

omg it sux

Just kidding mate :) It looks awesome.


BBS Signature
henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to Php: Managing IP addresses 2006-03-17 08:44:49 Reply

The page doesn't stop executing after the header is changed.
A hacker only have to use a http filter that filters all redircts to google.
You need to stop more of the page from being executed.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

Storm
Storm
  • Member since: May. 19, 2006
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Php: Managing IP addresses 2006-07-29 16:30:02 Reply

At 3/17/06 11:28 AM, Ca1um wrote: After the user is redirected to Google the script will die :)

Poor old script! =P

Anyway, nice job. This is usefull for stuff like IP banning, right?
And what happens if someone changes thier IP (if its possible...)?

cherries
cherries
  • Member since: Jun. 7, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to Php: Managing IP addresses 2006-07-29 18:37:48 Reply

or:

<?
$ips = array ('41556414', '556677');
$ip = $_SERVER['REMOTE_ADDR'];

if (in_array($ip, $ips)) {
echo "<h1>YOU ARE TEH BANNED!11</h1>";
exit;
}
?>

DarkMana
DarkMana
  • Member since: Apr. 4, 2005
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to Php: Managing IP addresses 2006-07-30 10:56:28 Reply

At 7/29/06 04:30 PM, --Storm-- wrote: And what happens if someone changes thier IP (if its possible...)?

I think it's possible by going into the command prompt and removing your current IP address and then renewing it. I've done it before, but I didn't pay attention to if the address actually changed.


Asus P5Q PRO, Intel E8400 @ 3.60 GHz, 4GB DDR2-1000, ATI HD4850

BBS Signature
elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Php: Managing IP addresses 2006-07-30 10:57:49 Reply

Normally you should get a new IP every time you reconnect to the internet.


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature
thecoshman
thecoshman
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to Php: Managing IP addresses 2006-08-08 08:48:27 Reply

At 7/30/06 10:57 AM, elbekko wrote: Normally you should get a new IP every time you reconnect to the internet.

Not always true, if you use a dial-up modem, tehn every time you connect you do get a new ip.

if you use adsl, you tend to get the same ip for a while, but it can change.

if you havve proper broad band, like blue yonder or what have you, you are given a fixed ip, it is your ip for ever and ever!

thecoshman
thecoshman
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to Php: Managing IP addresses 2006-11-06 17:52:07 Reply

with this thing though, if you have a form that user clicks submit on, that take them to antother page. i think these seems to get the ip of the requesting thing, which in this case seems to be the server. cose i keep loging that same ip addres for a few people, which of couse is higly unlikly. would i need to get their ip befor hand, and post that data with the form as a hidden variable?

Mister-Mind
Mister-Mind
  • Member since: Jul. 1, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Php: Managing IP addresses 2007-02-16 11:47:06 Reply

At 7/29/06 06:37 PM, cherries wrote: or:

<?
$ips = array ('41556414', '556677');
$ip = $_SERVER['REMOTE_ADDR'];

if (in_array($ip, $ips)) {
echo "<h1>YOU ARE TEH BANNED!11</h1>";
exit;
}
?>

or

<?php
$ban_ip = ("xxx.xxx.xxx");
$visitor_ip = $_SERVER['REMOTE_ADDR'];
$ip_list = explode(",", $ban_ip);
foreach($ip_list as $ip)
{
if($visitor_ip == $ip)
{
die("<h2> YOUR BANNED!");
}
}

?>

different
different
  • Member since: Jul. 8, 2004
  • Offline.
Forum Stats
Member
Level 35
Blank Slate
Response to Php: Managing IP addresses 2007-02-16 12:39:11 Reply

Switch can come in handy...

<?php
$ipaddress = $_SERVER['REMOTE_ADDR']; // Sets the variable to the users IP address
switch ($ipaddress) {
case "xxx.xxx.xxx": // This checks to see if an IP address is whatever
echo "[b][u]Hello webmaster![/b][/u]"; // If the user has that IP address, it will echo this
break;
case "xxx.xxx.xxx": // Checks to see if that is the IP address of the user
echo "This is a special message! <br> You are cool!"; // If the user has that IP address, it will echo this
break;
case "xxx.xxx.xxx": // Checks to see if that is the IP address of the user
header('Location: http://www.google.com/'); // If the user dose have this IP address the header will be changed to google.com and they will be redirected
die();
break;
default: // If their IP address is anything else
echo ""; // Then it will echo nothing
break;
}
?>


> twitter.

Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to Php: Managing IP addresses 2007-05-10 21:58:20 Reply

Well I'm trying to use this to check IP,and if it is a certain IP(like in this tutorial),it will redirect,but I'm getting an error.

Error on index,top of page

I'm including a file with the code:

<?
$ip = $_SERVER['REMOTE_ADDR'];
$ip2 = $ip;

if($ip == $ip2){
header('Location:http://the-toon.net/banned.p hp/');
}
?>

In the code,it will just refer the person because the redirection IP is whoever visits the page(just for testing).


wat
a compessor wil raise the volume while lowering the db - chronamut

DFox
DFox
  • Member since: Aug. 9, 2003
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to Php: Managing IP addresses 2007-05-10 22:03:00 Reply

At 5/10/07 09:58 PM, Thomas wrote: In the code,it will just refer the person because the redirection IP is whoever visits the page(just for testing).

Any header modification must be done before anything is outputted to the browser.

If you can't do that, then check out output buffering in PHP: Main.


BBS Signature