I want to get one colume data (IP address) from one of mysql table and then use a function to change it to hex number and then update/insert it into a new mysql table, but my code is just won't work, the value $hexaF can be print out but my if function won't work. I really don't know why. I'm sure it's my coding problem. (I'm newbie.)
I'm running FoxServ 3.0 (apache v2.0.39, php v4.2.2 and mysql v3.23.36) with phpnuke 6.0.
Any helps or comments I would greatly appreciated. thx in advance. 🙂
here is my code:
include("header.php");
global $post_id, $hexaF, $post_idF, $hexaFinal, $dbi, $user_prefix;
$result = sql_query("select post_id,poster_ip from ".$user_prefix."_nuke_posts2 where post_id < 11 order by post_id", $dbi);
while($nuke_posts = sql_fetch_array($result, $dbi)) {
$post_id = $nuke_posts[post_id];
$ipa = $nuke_posts[poster_ip];
DecToHex($post_id,$ipa);
}
function DecToHex ($post_id,$ipa) {
global $post_id, $hexaF, $post_idF, $hexaFinal;
$ipt = strtok($ipa,"...");
while ($ipt !== FALSE) {
$iptl[] = $ipt ;
$ipt = strtok("...");
}
list($k,$v) = each($iptl);
while (list($k,$v) = each($iptl)) {
if ($k == 0) {
$hexa = base_convert ($v, 10, 16);
if (strlen($hexa) < 2) {
$hexa = substr_replace ($hexa, '0', -1, 0);
$hexa0 = "$hexa";}
else {$hexa0 = "$hexa";}
}
elseif ($k == 1) {
$hexa = base_convert ($v, 10, 16);
if (strlen($hexa) < 2) {
$hexa = substr_replace ($hexa, '0', -1, 0);
$hexa1 = "$hexa";}
else {$hexa1 = "$hexa";}
}
elseif ($k == 2) {
$hexa = base_convert ($v, 10, 16);
if (strlen($hexa) < 2) {
$hexa = substr_replace ($hexa, '0', -1, 0);
$hexa2 = "$hexa";}
else {$hexa2 = "$hexa";}
}
else {
$hexa = base_convert ($v, 10, 16);
if (strlen($hexa) < 2) {
$hexa = substr_replace ($hexa, '0', -1, 0);
$hexa3 = "$hexa";}
else {$hexa3 = "$hexa";}
}
$hexaF = "$hexa0$hexa1$hexa2$hexa3";
} // end while
echo "$post_idF --- $hexaF";
echo " <-- yea, it's length eight<br>\n";
while (strlen($hexaF) == 8) {
echo " <-- yea, it's length eight<br>\n";
// sql_query("insert into ".$user_prefix."_nuke_ip (post_id,poster_ip) values (NULL,'$hexaFinal')", $dbi);
if ($result) { echo "Seems Success.\n";}
else {echo "failed.";}
} // end if
} // end function