php help/maybe contract hire
Subject : php help/maybe contract hire
From: email@hidden
Date: Fri, 10 Mar 2006 10:16:25 -0600
Delivered-to: email@hidden
Delivered-to: email@hidden
Hey folks,
My php skills are not real sharp, and my usual php guy is getting on
a sailboat in a few days for the next 8 months (lucky dog!). So I
need a little help.
I run a small LAN/ISP with about 25 customers, and I need to charge
based on bandwidth use. I've got the raw data dumping into a mysql
db - that part's working great. But the php script I have for
pulling the data out and collating it doesn't do exactly what I need.
So I'm looking to 'audition' someone by getting them to do a little
of my dirty work for me. I'll pay a reasonable fee for it. If you
know php well, it shouldn't really take you long.
The script below currently returns two tables, one for upload and one
for download, sorted by IP and within that by date, for a range of IP
addresses.
What I need it to return is upload mb, download mb, and total mb per
day for the given time period for each IP, plus total for that IP for
the time period, plus the systemwide total mb uploaded + downloaded
and the average per IP systemwide. Ideally I'd like to be able to
exclude certain IP addresses, but that's not as critical as I can
probably work around that with the IP range I enter for the most
part. If it can build charts showing each IP's daily info, all the
better.
Contact me offlist with any solutions/questions.
Thanks.
Here's the existing script:
<?php
/*
IP Accounting System v1
Copyright ©2002 - Family Entertainment Network, LLC
Eje Gustafsson - email@hidden
http://www.fament.com/
All rights reserved
This program is free to use, distribute and modify as long as
copyright and credits are given to the author of this script
Donations are welcomed if you find this application useful
Paypal send money to email@hidden or just simply use
the link below;
https://www.paypal.com/xclick/business=email@hidden&item_name=Accounting+Collector
If someone want feel free to update this and send me a fixed copy.
Don't forget to set your db username and db password below and the
database to use if you are not using the one suggested in Accounting Collector.
Release notes 3.01 1/2005
added configuration file config.data for index.php
configuration data for the 2 perl programs need be changed there
----------------------------------------------------------------------------------------
*/
global $_GET, $_POST;
// read configuration data
require("configure.php");
define(DEBUG, intval($_GET["debug"] + $_POST["debug"])>0 ); // set
to 1 for debug output
/*
No changes are neccessary below this line!
Last Changes done 10/2004 by email@hidden
****************************************************************************/
// for testing set to 1
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
error_reporting(E_CORE_ERROR|E_PARSE|E_COMPILE_ERROR);
//$errorlevel = E_CORE_ERROR|E_PARSE|E_COMPILE_ERROR|E_USER_ERROR;
//error_reporting($errorlevel); //set to 63 to show all errors, 6
for BIG errors, 0 shows no errors
$Submit = $_POST["Submit"];
if (!isset($_POST["month"]))
{ $month = $lmonth = date("m");
$year = $lyear = date("Y");
//$day = $lday = (date("d")-1);
$day = $lday = date("d");
//$lday = "31";
}
else
{
$ip = $_POST["ip"];
$year = $_POST["year"];
$lyear = $_POST["lyear"];
$month = $_POST["month"];
$lmonth = $_POST["lmonth"];
$day = $_POST["day"];
$lday = $_POST["lday"];
$subdaily = $_POST["subdaily"];
$submonthly= $_POST["submonthly"];
$showdetails = $_POST["showdetails"];
$showdomains = $_POST["showdomains"];
$showpppoe = $_POST["showpppoe"];
$showerrors = $_POST["showerrors"];
$showtoday = $_POST["showtoday"];
}
?>
<html>
<head>
<title>IP based Bandwidth Accounting for StarOS Routers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="accounting" method="post" action="">
<input type="hidden" name="debug" value="<?=DEBUG?>">
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td><b>Period from</b>:</td>
<td>
<select name="year" id="year">
<option value="" <?php if (!$year) echo "selected"; ?>>All</option>
<?
for ($cnt=-3;$cnt<1;$cnt++)
{
print '<option value="' . (date("Y")+$cnt) . '"';
if ( $year==(date("Y")+$cnt) ) print " selected";
print ">".(date("Y")+$cnt)."</option>\n";
}
?>
</select></td>
<td>
<select name="month" id="month">
<option value="01" <?php if ($month=="01") echo "selected";
if (!$month) echo "selected"; ?>>Jan</option>
<option value="02" <?php if ($month=="02") echo "selected";
?>>Feb</option>
<option value="03" <?php if ($month=="03") echo "selected";
?>>Mar</option>
<option value="04" <?php if ($month=="04") echo "selected";
?>>Apr</option>
<option value="05" <?php if ($month=="05") echo "selected";
?>>May</option>
<option value="06" <?php if ($month=="06") echo "selected";
?>>Jun</option>
<option value="07" <?php if ($month=="07") echo "selected";
?>>Jul</option>
<option value="08" <?php if ($month=="08") echo "selected";
?>>Aug</option>
<option value="09" <?php if ($month=="09") echo "selected";
?>>Sep</option>
<option value="10" <?php if ($month=="10") echo "selected";
?>>Oct</option>
<option value="11" <?php if ($month=="11") echo "selected";
?>>Nov</option>
<option value="12" <?php if ($month=="12") echo "selected";
?>>Dec</option>
</select></td>
<td>
<select name="day" id="day">
<option value="01" <?php if ($day=="01") echo "selected";
if (!$day) echo "selected"; ?>>01</option>
<option value="02" <?php if ($day=="02") echo "selected";
?>>02</option>
<option value="03" <?php if ($day=="03") echo "selected";
?>>03</option>
<option value="04" <?php if ($day=="04") echo "selected";
?>>04</option>
<option value="05" <?php if ($day=="05") echo "selected";
?>>05</option>
<option value="06" <?php if ($day=="06") echo "selected";
?>>06</option>
<option value="07" <?php if ($day=="07") echo "selected";
?>>07</option>
<option value="08" <?php if ($day=="08") echo "selected";
?>>08</option>
<option value="09" <?php if ($day=="09") echo "selected";
?>>09</option>
<option value="10" <?php if ($day=="10") echo "selected";
?>>10</option>
<option value="11" <?php if ($day=="11") echo "selected";
?>>11</option>
<option value="12" <?php if ($day=="12") echo "selected";
?>>12</option>
<option value="13" <?php if ($day=="13") echo "selected";
?>>13</option>
<option value="14" <?php if ($day=="14") echo "selected";
?>>14</option>
<option value="15" <?php if ($day=="15") echo "selected";
?>>15</option>
<option value="16" <?php if ($day=="16") echo "selected";
?>>16</option>
<option value="17" <?php if ($day=="17") echo "selected";
?>>17</option>
<option value="18" <?php if ($day=="18") echo "selected";
?>>18</option>
<option value="19" <?php if ($day=="19") echo "selected";
?>>19</option>
<option value="20" <?php if ($day=="20") echo "selected";
?>>20</option>
<option value="21" <?php if ($day=="21") echo "selected";
?>>21</option>
<option value="22" <?php if ($day=="22") echo "selected";
?>>22</option>
<option value="23" <?php if ($day=="23") echo "selected";
?>>23</option>
<option value="24" <?php if ($day=="24") echo "selected";
?>>24</option>
<option value="25" <?php if ($day=="25") echo "selected";
?>>25</option>
<option value="26" <?php if ($day=="26") echo "selected";
?>>26</option>
<option value="27" <?php if ($day=="27") echo "selected";
?>>27</option>
<option value="28" <?php if ($day=="28") echo "selected";
?>>28</option>
<option value="29" <?php if ($day=="29") echo "selected";
?>>29</option>
<option value="30" <?php if ($day=="30") echo "selected";
?>>30</option>
<option value="31" <?php if ($day=="31") echo "selected";
?>>31</option>
</select></td>
<td> <b>until</b> </td>
<td>
<select name="lyear" id="lyear">
<option value="" <?php if (!$lyear) echo "selected"; ?>>All</option>
<?
for ($cnt=-3;$cnt<1;$cnt++)
{
print '<option value="' . (date("Y")+$cnt) . '"';
if ( $lyear==(date("Y")+$cnt) ) print " selected";
print ">".(date("Y")+$cnt)."</option>\n";
}
?>
</select></td>
<td>
<select name="lmonth" id="lmonth">
<option value="01" <?php if ($lmonth=="01") echo
"selected"; if (!$lmonth) echo "selected"; ?>>Jan</option>
<option value="02" <?php if ($lmonth=="02") echo
"selected"; ?>>Feb</option>
<option value="03" <?php if ($lmonth=="03") echo
"selected"; ?>>Mar</option>
<option value="04" <?php if ($lmonth=="04") echo
"selected"; ?>>Apr</option>
<option value="05" <?php if ($lmonth=="05") echo
"selected"; ?>>May</option>
<option value="06" <?php if ($lmonth=="06") echo
"selected"; ?>>Jun</option>
<option value="07" <?php if ($lmonth=="07") echo
"selected"; ?>>Jul</option>
<option value="08" <?php if ($lmonth=="08") echo
"selected"; ?>>Aug</option>
<option value="09" <?php if ($lmonth=="09") echo
"selected"; ?>>Sep</option>
<option value="10" <?php if ($lmonth=="10") echo
"selected"; ?>>Oct</option>
<option value="11" <?php if ($lmonth=="11") echo
"selected"; ?>>Nov</option>
<option value="12" <?php if ($lmonth=="12") echo
"selected"; ?>>Dec</option>
</select></td>
<td>
<select name="lday" id="lday">
<option value="01" <?php if ($lday=="01") echo "selected";
if (!$lday) echo "selected"; ?>>01</option>
<option value="02" <?php if ($lday=="02") echo "selected";
?>>02</option>
<option value="03" <?php if ($lday=="03") echo "selected";
?>>03</option>
<option value="04" <?php if ($lday=="04") echo "selected";
?>>04</option>
<option value="05" <?php if ($lday=="05") echo "selected";
?>>05</option>
<option value="06" <?php if ($lday=="06") echo "selected";
?>>06</option>
<option value="07" <?php if ($lday=="07") echo "selected";
?>>07</option>
<option value="08" <?php if ($lday=="08") echo "selected";
?>>08</option>
<option value="09" <?php if ($lday=="09") echo "selected";
?>>09</option>
<option value="10" <?php if ($lday=="10") echo "selected";
?>>10</option>
<option value="11" <?php if ($lday=="11") echo "selected";
?>>11</option>
<option value="12" <?php if ($lday=="12") echo "selected";
?>>12</option>
<option value="13" <?php if ($lday=="13") echo "selected";
?>>13</option>
<option value="14" <?php if ($lday=="14") echo "selected";
?>>14</option>
<option value="15" <?php if ($lday=="15") echo "selected";
?>>15</option>
<option value="16" <?php if ($lday=="16") echo "selected";
?>>16</option>
<option value="17" <?php if ($lday=="17") echo "selected";
?>>17</option>
<option value="18" <?php if ($lday=="18") echo "selected";
?>>18</option>
<option value="19" <?php if ($lday=="19") echo "selected";
?>>19</option>
<option value="20" <?php if ($lday=="20") echo "selected";
?>>20</option>
<option value="21" <?php if ($lday=="21") echo "selected";
?>>21</option>
<option value="22" <?php if ($lday=="22") echo "selected";
?>>22</option>
<option value="23" <?php if ($lday=="23") echo "selected";
?>>23</option>
<option value="24" <?php if ($lday=="24") echo "selected";
?>>24</option>
<option value="25" <?php if ($lday=="25") echo "selected";
?>>25</option>
<option value="26" <?php if ($lday=="26") echo "selected";
?>>26</option>
<option value="27" <?php if ($lday=="27") echo "selected";
?>>27</option>
<option value="28" <?php if ($lday=="28") echo "selected";
?>>28</option>
<option value="29" <?php if ($lday=="29") echo "selected";
?>>29</option>
<option value="30" <?php if ($lday=="30") echo "selected";
?>>30</option>
<option value="31" <?php if ($lday=="31") echo "selected";
?>>31</option>
</select></td>
<td> Subtotal per day <input type="checkbox" name="subdaily"
value="1" <?php if ($subdaily) echo "checked";?>></td>
<td> per month <input type="checkbox" name="submonthly"
value="1" <?php if ($submonthly) echo "checked";?>></td>
<td> Today <input type="checkbox" name="showtoday" value="1"
<?php if ($showtoday) echo "checked";?>></td>
</tr>
<tr>
<td><b>IP No.</b></td>
<td colspan="2"><input name="ip" size="15" type="text"
value="<? if($ip){echo $ip;} ?>">
</td>
<td colspan="6">Show:
Details <input type="checkbox" name="showdetails"
value="1" <? if($showdetails) echo
"checked";?>>
Domains <input type="checkbox" name="showdomains"
value="1" <? if($showdomains &&
$showdetails) echo "checked";?>>
PPPoE <input type="checkbox" name="showpppoe"
value="1" <? if($showpppoe &&
$showdetails) echo "checked";?>>
Errors <input type="checkbox" name="showerrors"
value="1" <? if($showerrors) echo "checked";?>>
</td>
<td> </td>
<td><div align="right">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
</form>
<hr>
<table width="100%" valign="top">
<tr><td>
<?
$today = $showtoday || ($lday == date("d") && $day == date("d") &&
$lmonth == date("m") && $lmonth==$month && $lyear==$year && $lyear
== date("Y") );
$where = "";
// echo 'today= ';
// echo $today;
if (!empty($year))
{
$timestr = strtotime("$year$month$day");
$where = "WHERE (timemark >= $timestr)";
}
// echo 'timestr= ';
// echo $timestr;
if (!empty($lyear))
{ if (!empty($year)) { $where .= " AND " ;} else { $where = "WHERE ";}
$timestr = strtotime("$lyear$lmonth$lday");
$where .= "(timemark <= $timestr)";
}
if ( $today )
{ ///$queryupload = "delete from tmp";
///Get_mysql_Data($queryupload);
///$queryupload = "CREATE temporary TABLE tmp select * from
$outtable where datacount<0";
///Get_mysql_Data($queryupload);
//$queryupload = "insert into tmp (timemark, datahost,
datacount, packetcount) select unix_timestamp(curdate()), datahost,
sum(datacount), sum(packetcount) from $outtable group by datahost";
//$queryupload = "insert into tmp (timemark, datahost,
datacount, packetcount) select timemark, datahost, datacount,
packetcount from $outtable GROUP by datahost,timemark";
///$queryupload = "insert into tmp (timemark, datahost,
datacount, packetcount) select timemark, datahost, sum(datacount),
sum(packetcount) from $outtable GROUP BY
FROM_UNIXTIME(timemark,'%h%i'),datahost";
///Get_mysql_Data($queryupload);
//$queryupload = "SELECT * FROM tmp GROUP by timemark ORDER BY
datahost,timemark ";
///$queryupload = "SELECT * FROM tmp ORDER BY datahost,timemark";
}
else
{ $queryupload = "SELECT * FROM $dailyout $where GROUP BY
timemark, datahost ORDER BY datahost, timemark"; }
$resultupload = Get_mysql_Data($queryupload);
if ($resultupload)
{ $num_resultsupload = mysql_num_rows($resultupload); }
echo "<br>num_resultsupload="; echo $num_resultsupload;
if ( $today )
{ ///$querydownload = "CREATE temporary TABLE tmp2 select * from
$intable where datacount<0";
///Get_mysql_Data($querydownload);
//$querydownload = "insert into tmp2 (timemark, datahost,
datacount, packetcount) select unix_timestamp(curdate()), datahost,
sum(datacount), sum(packetcount) from $intable group by datahost";
///$querydownload = "insert into tmp2 (timemark, datahost,
datacount, packetcount) select timemark, datahost, sum(datacount),
sum(packetcount) from $intable GROUP by timemark, datahost";
//Get_mysql_Data($querydownload);
//$querydownload = "SELECT * FROM tmp2 ORDER BY datahost,timemark";
}
else
{ $querydownload = "SELECT * FROM $dailyin $where GROUP BY
timemark, datahost ORDER BY datahost, timemark"; }
$resultdownload = Get_mysql_Data($querydownload);
if ($resultdownload)
{ $num_resultsdownload = mysql_num_rows($resultdownload); }
echo "<br>num_resultsdownload="; echo $num_resultsdownload;
?>
<table border="1" cellspacing="1" cellpadding="1">
<tr><th colspan="4">Downloads</th></tr>
<?
$theader = "";
$pppoe = "";
$bytes = 0;
$packets = 0;
$TBytes = 0;
$TPackets = 0;
$dailyBytes = 0;
$monthlyBytes = 0;
$dailyPackets = 0;
$monthlyPackets= 0;
$curDay = 0;
$curMonth = 0;
$Today = date("d-M-Y",unixtime);
if ($num_resultsdownload)
{
ProcessData("Download","DL",$resultdownload);
if (DEBUG) print "<tr><td colspan=\"4\"><b>SQL Query</b>:
$querydownload</td></tr>\n";
}
?>
</table>
</td><td>
<table border="1" cellspacing="1" cellpadding="1">
<tr><th colspan="4">Uploads</th></tr>
<?
$theader = "";
$pppoe = "";
$bytes = 0;
$packets = 0;
$TBytes = 0;
$TPackets = 0;
$dailyBytes = 0;
$monthlyBytes = 0;
$dailyPackets = 0;
$monthlyPackets= 0;
$curDay = 0;
$curMonth = 0;
$Today = date("d-M-Y",unixtime);
if ($num_resultsupload)
{
ProcessData("Upload","UL", $resultupload);
if (DEBUG) print "<tr><td colspan=\"4\"><b>SQL Query</b>:
$queryupload</td></tr>\n";
}
?>
</table>
</td></tr>
</table>
</body>
</html>
<?
/*****************************************************************************/
function ProcessData($subject="Download", $short="DL", $DBresults)
{
global $ip, $showpppoe, $showdetails, $showdomains, $showerrors,
$bytes,$packets ,$TBytes,$TPackets, $subdaily,
$submonthly, $dailyBytes,$monthlyBytes, $dailyPackets,
$monthlyPackets, $curDay, $curMonth, $Today, $today;
if ( $showpppoe ) $pppoe = "<td>PPPoE User</td>\n";
if ($showdetails) $theader = "<td>Date</td>\n<td>IP No.</td>\n";
else $theader = "<td colspan=\"2\"> </td>";
echo <<<EOD
<tr style="font-weight:bold;border:2px solid;color:darkgreen">
$theader
<td align="right"><b>MBytes $short</b></td>
<td align="right">K-Packets</td>
$pppoe
</tr>
EOD;
while ( $oData = mysql_fetch_object($DBresults) )
{
$datahost = $oData->datahost;
if ( $ip )
{
if ( !testip($ip,$datahost) ) continue;
}
if ( $showerrors && is_LocalIP($datahost) ) continue;
if ( !$showerrors && !is_LocalIP($datahost) ) continue;
if ( $today )
//$DateStr = date("H:m",$oData->timemark);
$DateStr = date("H:i",$oData->timemark);
else
$DateStr = date("Y-M-d",$oData->timemark);
$timestr = date($oData->timemark);
$bytes = $oData->datacount;
$packets = $oData->packetcount;
$TBytes += $bytes;
$TPackets+= $packets;
ShowSubTotal($timestr,0);
if ($showdetails)
{
$Fbytes = number_format($bytes/1024/1024,3);
$Fpackets = number_format($packets/1024,2);
if ( $showpppoe ) $pppoe = "<td>$oData->pppoeuser</td>\n";
if ( $showdomains )
{ $domain = gethostbyaddr($datahost);
if ( strcasecmp($datahost, $domain) )
{ $datahost .= " - $domain"; }
}
echo <<<EOD
<tr>
<td>$DateStr</td>
<td>$datahost</td>
<td align="right">$Fbytes</td>
<td align="right">$Fpackets</td>
$pppoe
</tr>
EOD;
}
}
ShowSubTotal($timestr,1);
$FTBytes = number_format($TBytes/1024/1024,2);
$FTPackets= number_format($TPackets/1024,2);
echo <<<EOD
<tr style="font-weight:bold;border:2px solid;color:darkgreen">
<td>$subject MB</td>
<td colspan="2" align="right"> $FTBytes</td>
<td colspan="1" align="right">$FTPackets</td>
</tr>
EOD;
return;
}
/*****************************************************************************/
function ShowSubTotal($unixtime, $eof)
{
global $ip, $bytes,$packets ,$TBytes,$TPackets, $timestr,
$subdaily, $submonthly, $Today,
$dailyBytes,$monthlyBytes, $dailyPackets, $monthlyPackets,
$curDay, $curMonth;
if ( empty($curDay) )
{ $curDay = date("d",$unixtime);
$curMonth = date("M",$unixtime);
$Today = date("d-M-Y",$unixtime);
//return;
}
if ( $curDay == date("d",$unixtime) && !$eof)
{
$dailyBytes += $bytes;
$dailyPackets += $packets;
}
elseif ( $subdaily)
{
$dailyBytes = number_format($dailyBytes/1024/1024,3);
$dailyPackets = number_format($dailyPackets/1024,2);
echo <<<EOD
<tr style="font-weight:bold;border:1px solid;color:darkblue">
<td colspan="2">subtotal for $Today</td>
<td align="right">$dailyBytes</td>
<td align="right">$dailyPackets</td>
<td colspan="1"> </td>
</tr>
EOD;
$dailyBytes = 0;
$dailyPackets = 0;
$curDay = date("d",$unixtime);
$Today = date("d-M-Y",$unixtime);
}
if ( $curMonth == date("M",$unixtime) && !$eof)
{
$monthlyBytes += $bytes;
$monthlyPackets+= $packets;
}
elseif ( $submonthly )
{
$monthlyBytes = number_format($monthlyBytes/1024/1024,2);
$monthlyPackets = number_format($monthlyPackets/1024,2);
$ThisMonth = date("M-Y",$timestr);
echo <<<EOD
<tr style="font-weight:bold;border:1px solid;color:darkblue">
<td colspan="2">subtotal for $curMonth</td>
<td align="right">$monthlyBytes</td>
<td align="right">$monthlyPackets</td>
<td colspan="1"> </td>
</tr>
EOD;
$monthlyBytes = 0;
$monthlyPackets= 0;
$curMonth = date("M",$unixtime);
}
return;
}
/*****************************************************************************/
function Get_mysql_Data( $query, $results=0 )
{
global $hostname, $database, $user, $password;
// Connects to mySQL server
$dbLink = mysql_connect( $hostname, $user, $password )
or die("Unable to connect to MySQL on $hostname for user $user!");
// Connects to List Menu database
mysql_select_db( $database, $dbLink)
or die("Unable to select database $database !");
// Opens the recordset
return mysql_query($query, $dbLink);
}
/*****************************************************************************/
# determine if an IP address is within
# a particular network with mask
function is_LocalIP($datahost) {
global $localnet;
foreach ($localnet as $network)
{
if ( testip($network, $datahost) )
return 1;
}
return 0;
}
/*****************************************************************************/
function testip($range,$ip) {
$result = 1;
# IP Pattern Matcher
# J.Adams <email@hidden>
#
# Matches:
#
# xxx.xxx.xxx.xxx (exact)
# xxx.xxx.xxx.[yyy-zzz] (range)
# xxx.xxx.xxx.xxx/nn (nn = # bits, cisco style -- i.e. /24 = class C)
#
# Does not match:
# xxx.xxx.xxx.xx[yyy-zzz] (range, partial octets not supported)
if (ereg("([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/([0-9]+)",$range,$regs)) {
# perform a mask match
$ipl = ip2long($ip);
$rangel = ip2long($regs[1] . "." . $regs[2] . "." . $regs[3] .
"." . $regs[4]);
$maskl = 0;
for ($i = 0; $i< 31; $i++) {
if ($i < $regs[5]-1) {
$maskl = $maskl + pow(2,(30-$i));
}
}
if (($maskl & $rangel) == ($maskl & $ipl)) {
return 1;
} else {
return 0;
}
} else {
# range based
$maskocts = split("\.",$range);
$ipocts = split("\.",$ip);
# perform a range match
for ($i=0; $i<4; $i++) {
if (ereg("\[([0-9]+)\-([0-9]+)\]",$maskocts[$i],$regs)) {
if ( ($ipocts[$i] > $regs[2]) || ($ipocts[$i] < $regs[1])) {
$result = 0;
}
}
else
{
if ($maskocts[$i] <> $ipocts[$i]) {
$result = 0;
}
}
}
}
return $result;
}
/*****************************************************************************/
# determine if an IP address is within
# a particular network with mask
function IP_Match($network, $mask, $ip) {
$ip_long=ip2long($ip);
$network_long=ip2long($network);
$mask_long=ip2long($mask);
print "ip_long, network_long, mask_long: $ip_long, $network_long,
$mask_long<br>\n";
if (($ip_long & $mask_long) == $network_long) {
return true;
} else {
return false;
}
}
/*****************************************************************************/
?>
--
Bill Christensen
<http://greenbuilder.com/contact/ >
Green Building Professionals Directory: <http://directory.greenbuilder.com >
Sustainable Building Calendar: <http://www.greenbuilder.com/calendar/ >
Green Real Estate: <http://www.greenbuilder.com/realestate/ >
Straw Bale Registry: <http://sbregistry.greenbuilder.com/ >
Books/videos/software: <http://bookstore.greenbuilder.com/ >
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Web-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/web-dev/email@hidden
This email sent to email@hidden
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.