Page 1 of 1

compare iterated values

Posted: Sun Oct 09, 2005 3:47 pm
by SidewinderX
How do i compare the value of a pervious iteration with the value of the current iteration?

Code: Select all

<?php
function <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>() {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://nw4.novaworld.net/NWStats.dll');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies');
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
}
function getbannedcookie() {
for ($i = 0; $i < 100000; $i+=40){

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://nw4.novaworld.net/NWStats.dll?success=bhd_6_name.htm&failure=bhd_6_main.htm&relay=bhd_6_relay.htm&msgbase=bhd_6_msg.htm&nodb=bhd_6_nodb.htm&statpage=bhd_6_stat.htm&pfid=26&statslot=0&action=charlist&top=' . $i . '&pattern=A');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $result = curl_exec($ch);
        curl_close($ch);
}
}
function parseit($file) {
global $matches;
preg_match('/<TD Align="left" Width=150><A HREF="NWStats.dll\?success=bhd_6_stat.htm\&failure=bhd_6_main.htm\&relay=bhd_6_relay.htm\&msgbase=bhd_6_msg.htm\&nodb=bhd_6_nodb.htm\&statpage=bhd_6_stat.htm\&pfid=26\&statslot=0\&action=stats\&showchid=(.*?)">(.*?)<\/A><\/TD>/', $file, $matches);


}
getbannedcookie();
parseit(<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>());

echo $matches[1];
?>
which parses an id number. However after so many iterations (unknown) the id number before and after the iteration will be the same. I assume i have to create an 'if statement' which will compare the new id with the old id and when they are equal break the loop. So how do I store a previous value and compare it with the current value if after every iteration it replaces the old value is replaced with the new one?

Posted: Mon Oct 10, 2005 10:39 am
by SidewinderX
ok i spent a lot of time thinking about this. i edited my code so it iterates the value, compares the iterated value with the value in the database if they are equal it stops the iteration, if they are not equal it adds the new value to the database and restarts the iteration. i believe thats what i want done and i believe that is what i coded...but it dosnt work

Code: Select all

<?php 
function smurf() { 
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, 'http://nw4.novaworld.net/NWStats.dll'); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies'); 
        $result = curl_exec($ch); 
        curl_close($ch); 
        return $result; 
} 
function getbannedcookie($file) { 

$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname, $db);
$result = mysql_query("SELECT * FROM banned WHERE name='1'", $db);
$row = mysql_fetch_assoc($result);

for ($i = 0; $i < 10000; $i+=40){ 

        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, 'http://nw4.novaworld.net/NWStats.dll?success=bhd_6_name.htm&failure=bhd_6_main.htm&relay=bhd_6_relay.htm&msgbase=bhd_6_msg.htm&nodb=bhd_6_nodb.htm&statpage=bhd_6_stat.htm&pfid=26&statslot=0&action=charlist&top=' . $i . '&pattern=A'); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies'); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
        $result = curl_exec($ch); 
        curl_close($ch); 
preg_match('/<TD Align="left" Width=150><A HREF="NWStats.dll\?success=bhd_6_stat.htm\&failure=bhd_6_main.htm\&relay=bhd_6_relay.htm\&msgbase=bhd_6_msg.htm\&nodb=bhd_6_nodb.htm\&statpage=bhd_6_stat.htm\&pfid=26\&statslot=0\&action=stats\&showchid=(.*?)">(.*?)<\/A><\/TD>/', $file, $matches); 

if($matches[1] == $row['date']){
echo "Found on iteration " . $i;
break;
}
else{
$sql = mysql_query("UPDATE banned SET date='$matches[1]' WHERE name='1'") or die("Error: ".mysql_error());
}
} 


} 



getbannedcookie(smurf()); 

?>
after iteration 5700 or so the iterated values and the value in the database should be the same, but it dosnt seem to be working, any ideas?