ipreg/functions.php

46 lines
1.3 KiB
PHP

<?php
// strip mac address to 12 char string
function strip_mac($mac) {
$mac = str_replace('-', '', $mac);
$mac = str_replace(':', '', $mac);
$mac = str_replace('.', '', $mac);
$mac = str_replace(',', '', $mac);
$mac = str_replace(' ', '', $mac);
$mac = strtoupper($mac);
return ($mac);
}
// rebuild mac address
function write_mac($mac) {
if (strlen($mac)!=12) {
// if the MAC is empty, or for whatever reason incorrect, just return
return $mac;
} else {
// length is good, continue
$mac1 = substr($mac, 0, 2);
$mac2 = substr($mac, 2, 2);
$mac3 = substr($mac, 4, 2);
$mac4 = substr($mac, 6, 2);
$mac5 = substr($mac, 8, 2);
$mac6 = substr($mac, 10, 2);
// check session for preference (if 0, do nothing), if changed: update useredit.php too!
if ($_SESSION['suser_mac']==1) {
$mac = $mac1 . '-' . $mac2 . '-' . $mac3 . '-' . $mac4 . '-' . $mac5 . '-' . $mac6;
} else if ($_SESSION['suser_mac']==2) {
$mac = $mac1 . ':' . $mac2 . ':' . $mac3 . ':' . $mac4 . ':' . $mac5 . ':' . $mac6;
} else if ($_SESSION['suser_mac']==3) {
$mac = $mac1 . $mac2 . $mac3 . '-' . $mac4 . $mac5 . $mac6;
}
return $mac;
}
}
// redirect page
function header_location($location) {
header("location: " . $location);
exit;
}
?>