Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.
Moderator: General Moderators
redhair
Forum Contributor
Posts: 300 Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:
Post
by redhair » Fri Feb 20, 2004 5:52 am
Code: Select all
<?php
//check ip and decide who is admin.
$ip_visit = getenv("REMOTE_ADDR");
$ip_array[] = "127.0.0.1";
$ip_array[] = "192.168.1.1";
$ip_array[] = "192.168.1.2";
foreach ($ip_array as $ip_adm)
{
if (preg_match("/$ip_visit/","$ip_adm"))
{
$is_admin = "1";
session_register(is_admin);
}
}
?>
McGruff
DevNet Master
Posts: 2893 Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland
Post
by McGruff » Fri Feb 20, 2004 10:37 am
Unfortunately you can't use IP for authentication.
(1) dynamic IPs (and AOL users might change IP within the same session)
(2) NATs
(3) IP spoofing
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Fri Feb 20, 2004 11:00 am
Might be okay for an Intranet though?! Certain machines have access to certain pages.
Mark
McGruff
DevNet Master
Posts: 2893 Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland
Post
by McGruff » Fri Feb 20, 2004 11:28 am
Yes - wasn't thinking about intranets.
jad
Forum Newbie
Posts: 1 Joined: Fri Feb 27, 2004 8:58 am
Location: Middle East - Jordan
Contact:
Post
by jad » Fri Feb 27, 2004 8:58 am
hi folks
Well, I think it could be a great implementation to avoid session hijacking.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Feb 27, 2004 11:07 am
simplified version:
Code: Select all
$_allowed=array(
"127.0.0.1",
"192.168.1.1",
"192.168.1.2"
);
if(in_array($_SERVER["REMOTE_ADDR"],$_allowed))
$_SESSION["is_admin"]=true;
redhair
Forum Contributor
Posts: 300 Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:
Post
by redhair » Fri Feb 27, 2004 11:34 am
[quote="Weirdan"]simplified version:[/quote]
Better :)