Forum Topic: Php: Managing IP addresses

(1,381 views • 12 replies)

This topic is 1 page long.

<< < > >>
None

WoogieNoogie

Reply To Post Reply & Quote

Posted at: 3/16/06 06:47 PM

WoogieNoogie LIGHT LEVEL 14

Sign-Up: 06/26/05

Posts: 3,195

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 :)


None

DashDingo

Reply To Post Reply & Quote

Posted at: 3/16/06 08:50 PM

DashDingo EVIL LEVEL 14

Sign-Up: 06/25/04

Posts: 5,100

omg it sux

Just kidding mate :) It looks awesome.

BBS Signature

None

henke37

Reply To Post Reply & Quote

Posted at: 3/17/06 08:44 AM

henke37 NEUTRAL LEVEL 16

Sign-Up: 09/10/04

Posts: 2,627

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.

Move on to ActionScript 3! And please, drop the mysql PHP extension, it's so stale that it lacks features that is no longer considered new! Go mysqli or pdo instead.


None

Storm

Reply To Post Reply & Quote

Posted at: 7/29/06 04:30 PM

Storm EVIL LEVEL 05

Sign-Up: 05/19/06

Posts: 1,110

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...)?


None

cherries

Reply To Post Reply & Quote

Posted at: 7/29/06 06:37 PM

cherries LIGHT LEVEL 18

Sign-Up: 06/07/05

Posts: 4,561

or:

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

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


None

DarkMana

Reply To Post Reply & Quote

Posted at: 7/30/06 10:56 AM

DarkMana DARK LEVEL 23

Sign-Up: 04/04/05

Posts: 2,581

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.

CM 590; Intel E8400; ASUS P5Q Pro; Mushkin DDR2-1066 4GB; Radeon HD4850; Hitachi 500GB; WinXP.

BBS Signature

None

elbekko

Reply To Post Reply & Quote

Posted at: 7/30/06 10:57 AM

elbekko EVIL LEVEL 16

Sign-Up: 07/23/04

Posts: 6,450

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

[ PHP: Main | Omigod, a blog ]

BBS Signature

None

thecoshman

Reply To Post Reply & Quote

Posted at: 8/8/06 08:48 AM

thecoshman DARK LEVEL 11

Sign-Up: 06/11/06

Posts: 812

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!


None

thecoshman

Reply To Post Reply & Quote

Posted at: 11/6/06 05:52 PM

thecoshman DARK LEVEL 11

Sign-Up: 06/11/06

Posts: 812

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?


None

Mister-Mind

Reply To Post Reply & Quote

Posted at: 2/16/07 11:47 AM

Mister-Mind EVIL LEVEL 07

Sign-Up: 07/01/06

Posts: 2,212

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!");
}
}

?>


None

different

Reply To Post Reply & Quote

Posted at: 2/16/07 12:39 PM

different DARK LEVEL 35

Sign-Up: 07/08/04

Posts: 3,766

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;
}
?>

simple & minimal, that's my style.
thoughts on ux, usability & design


None

Thomas

Reply To Post Reply & Quote

Posted at: 5/10/07 09:58 PM

Thomas LIGHT LEVEL 13

Sign-Up: 02/14/05

Posts: 2,429

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).


None

DFox

Reply To Post Reply & Quote

Posted at: 5/10/07 10:03 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,270

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.


All times are Eastern Standard Time (GMT -5) | Current Time: 01:07 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!