Jump to content

ssjrocks

Members
  • Posts

    7
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

ssjrocks's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. so i made my own solution... function num2alph($num) { $space[0] = ' '; $spec = array("0" => "_", "1" => ".", "2" => "-"); $aZ09 = array_merge($space, range('A', 'Z'), range('a', 'z'),range(0, 9), $spec); $anum = ''; while($num >= 1) { $num = $num - 1; $anum = $aZ09[($num % count($aZ09))].$anum; $num = $num / count($aZ09); } return strtolower($anum); } function alphagen($start, $len) { foreach (range($start ,$len) as $i) { $string = num2alph($i); return $string; } }
  2. spot on man i get it now still spinnin out on that calculation to get the ascii codes ... i basicly need to be able to call $line = rangegenerator($i); it doesnt matter if the number associated to each char changes each time a diffrent charset is used
  3. and i would love to know what this does?? i am not that good at maths and got lost at the explanation of % as a math operator while($num >= 1) { $num = $num - 1; $anum = chr(($num % 26)+65).$anum; $num = $num / 26; }
  4. so i got 2 snippets the first works exactly as i need it to except its limited to lowecase .. im using a for loop that calls it like this $line = alphagen($i,$i); the bottom function works has a bigger range .. (and i can understand it .. i added the special chars bit) but it generates randoms with collisions is there a way to modify the first 2 functions to make it use a list or even an array so that i can interchange the charlist easier ( from form post) my favouriite would be if the second function could me modified to do pretty much what its doing now but in a sequential mannner eg echo alphagen(1); = a echo alphagen(2); = b echo alphagen(bignumber); = Arfg4_2 function num2alph($num) { $anum = ''; while($num >= 1) { $num = $num - 1; $anum = chr(($num % 26)+65).$anum; $num = $num / 26; } return strtolower($anum); } function alphagen($start, $len) { foreach (range($start ,$len) as $i) { $string = num2alph($i); return $string; } } ****************************************************************** function makepin($lenth) { // makes a random alpha numeric string of a given lenth $spec = array("0" => " ", "1" => "_", "2" => ".", "3" => "-"); $aZ09 = array_merge(range('A', 'Z'), range('a', 'z'),range(0, 9),$spec); $out =''; for($c=0;$c < $lenth;$c++) { $out .= $aZ09[mt_rand(0,count($aZ09)-1)]; } unset($az09,$lenth,$c); gc_collect_cycles(); return $out; }
  5. <?php $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $start = $time; $invalid = '0'; echo '<center><a href="view.php">Browse</a>|<a href="search.php">Search</a>|<a href="update.php">update</a>|</center><BR><BR><BR>'; echo str_repeat(' ', 256).'<pre>'; flush(); ob_start(); include('sql.php'); include('functions.php'); mysql_select_db($dbname, $con); $nh = '0'; $ru = '0'; if (!$con) { die('Could not connect: ' . mysql_error()); } $pp = $_POST["data"]; $delim = $_POST["delim"]; $last = '0'; $data = explode("\n", $pp); $resultf = array_unique($data); $tot = count($resultf); $dupl = count($data) - count($resultf); echo $dupl . ' Duplicates Removed... Processing ' . $tot . ' Records.'; echo '<BR><BR>'; create_progress(); $counter = '0'; foreach ($resultf as $line) { $plainpass = explode($delim, $line); ++$counter; if (md5($plainpass[1]) != $plainpass[0]){ ++$invalid; next($resultf); } if(recordExists('passhash',$plainpass[0])){ mysql_query("UPDATE megatable SET plainpass = '" . $plainpass[1] . "' WHERE passhash = '" . $plainpass[0] . "' AND plainpass = ''"); $ru = $ru + mysql_affected_rows(); } else{ mysql_query("INSERT INTO megatable (passhash, plainpass) VALUES ('" . $plainpass[0] . "', '" . $plainpass[1] . "')"); $nh = $nh + mysql_affected_rows(); } $prog = $counter / $tot * 100; $prog = round($prog); if($last != $prog){update_progress($prog);} $last = $prog; unset($resultf[$last]); } mysql_close($con); echo '<BR>done'; echo '<BR>' . $nh . ' New Hashes added to Db'; echo '<BR>' . $ru . 'Hashes Updated with plainpass'; echo '<BR>From ' . $tot . ' Unique inputs'; echo "<BR>" . $invalid . " Illegal Entries Ignored.<BR>"; echo '<BR><BR>'; $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 4); echo 'Page generated in '.$total_time.' seconds.'."\n"; ?> im having problems around the if (md5($plainpass[1]) != $plainpass[0]){ line if i import 5000 records it replies that 4999 are illegal entried ...(the md5 of the plainpass does not match data supplie... even tho i know it does) any help would be apreciated i have checked and i am sending clean data to the script no spaces \n's or anything like that
  6. i had very limited sucess with preg split so for compatibility i decided to explode the file on new line and preg split on all then crazy foreach loops
  7. hey guys, i need some help with importing a logfile into sql im sure there are tons easier ways to do every part of the script so i was hoping for a nudge in the right direction 1st is an example of the file im importing 1841526 19:41:01 22-12-09 POCSAG-4 NUMERIC 512 TONE ONLY 1841527 19:41:01 22-12-09 POCSAG-4 NUMERIC 512 TONE ONLY 0370377 19:41:05 22-12-09 POCSAG-3 ALPHA 1200 19:40 P101686..ADA2 0547216 19:41:11 22-12-09 POCSAG-1 ALPHA 1200 19:40 P90393..MSG1.MON.F2 0411456 19:41:16 22-12-09 POCSAG-3 ALPHA 1200 J230059,4.2,:HH130B 117,62 COLUMBIA CR MODBURY_NORTH,PETE"?)'agi 1517188 19:41:16 22-12-09 POCSAG-1 NUMERIC 1200 2578 1601773 19:41:16 22-12-09 POCSAG-4 NUMERIC 1200 TONE ONLY 0866741 19:41:16 22-12-09 POCSAG-3 NUMERIC 1200 TONE ONLY 0404958 19:41:16 22-12-09 POCSAG-2 NUMERIC 1200 TONE ONLY 0465590 19:41:16 22-12-09 POCSAG-2 NUMERIC 1200 2709 2058471 19:41:17 22-12-09 POCSAG-4 ALPHA 1200 v?v???ff.&?"? &6O?/?"G?&?BN??j?Nv??/?7O?.??/?J???~nNv>? >?N?2?n?"G? 0511406 19:41:18 22-12-09 POCSAG-3 ALPHA 1200 2212-19:40 CONTACT STATE GOVT SECURITY 07-3224-6666 RE ALARM 0847399 19:41:18 22-12-09 POCSAG-3 ALPHA 1200 19:40 P253441.SVRS2 as you can see thers alot of special chars coming through that i have to deal with hence the screwing around with mysql_real_escape_string and what not. and here is my script <?php $rimp = "0"; $dup = "0"; if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; $rndmna = rand(1, 256); if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. <BR>"; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $rndmna . $_FILES["file"]["name"]); echo "Renamed and Stored in: " . "upload/" . $rndmna . $_FILES["file"]["name"]; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } echo "<BR><br>Processing."; flush(); $con = mysql_connect("localhost","root","012142"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("spl1nt", $con); $spc = " "; $tcnt = ""; $filename = "upload/" . $_FILES["file"]["name"]; $fp = @fopen($filename, 'r'); if ($fp) { $array = explode("\n", fread($fp, filesize($filename))); } foreach ($array as $k => $v) { $tcnt ++; $tccnt = count($array); $fields = preg_split('//', $array[$k]); $fcnt = count($fields); // wow @ below.... gotta be an easier way if(isset($fields[0])){$fieldx[0] = $fields[0] . $fields[1] . $fields[2] . $fields[3] . $fields[4] . $fields[5] . $fields[6] . $fields[7];} if(isset($fields[9])){$fieldx[1] = $fields[9] . $fields[10] . $fields[11] . $fields[12] . $fields[13] . $fields[14] . $fields[15] . $fields[16];} if(isset($fields[17])){$fieldx[2] = $fields[18] . $fields[19] . $fields[20] . $fields[21] . $fields[22] . $fields[23] . $fields[24] . $fields[25];} if(isset($fields[27])){$fieldx[3] = $fields[27] . $fields[28] . $fields[29] . $fields[30] . $fields[31] . $fields[32] . $fields[33] . $fields[34];} if(isset($fields[36])){$fieldx[4] = $fields[36] . $fields[37] . $fields[38] . $fields[39] . $fields[40] . $fields[41] . $fields[42] . $fields[43];} if(isset($fields[43])){$fieldx[5] = $fields[43] . $fields[44] . $fields[45] . $fields[46] . $fields[47];} if(isset($fields[49])){$fieldx[6] = $fields[49] ;} //$fields[17] if($fields[0] >= 0){ $h=0; $tst1 = ''; foreach ($fields as $d) { if ($h > '49'){ $tst1 = $tst1 . $d; } $h++; } // $qry11 = "SELECT * FROM data WHERE Address='$fieldx[0]' and Date ='$fieldx[2]' and Msg='$tst1'"; // echo "<BR>pp" . $fieldx[0] . "pp"; echo "<BR>"; //echo "SELECT * FROM data WHERE Address='$fieldx[0]' and Date ='$fieldx[2]' and Msg='$tst1'";// echo "pp" . $fieldx[2] . "pp"; echo $checkstr; echo "<BR>" . $check . "<BR>" . mysql_num_rows($check); $checkstr = "SELECT * FROM data WHERE Address='$fieldx[0]' and Date ='$fieldx[2]' and Msg='$tst1'"; $check = mysql_query($checkstr,$con); if($fieldx[0] != "" || $fieldx[2] != "" || $tst1 != ""){ if(mysql_num_rows($check) >= 1) { $dup ++; } else; { if(mysql_num_rows($check) == 0) { if($tst1 == "- Smash -" ){break;} $tst1 = mysql_real_escape_string($tst1); $sqlqu="INSERT INTO Data (Address, Time , Date, p1234, Type, Baud, Msg) VALUES ('$fieldx[0]', '$fieldx[1]', '$fieldx[2]', '$fieldx[3]', '$fieldx[4]', '$fieldx[5]', '$tst1')"; $rimp ++; if (!mysql_query($sqlqu,$con)) { die('Error: ' . mysql_error()); } } } echo"."; } } } echo "<BR><BR>"; echo $rimp . " records imported"; echo "<BR>" . $dup . " Duplicates Ignored"; mysql_close($con); ?> it looks ugly as but im fairly new to this i keep getting Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\apache2\htdocs\doimp2.php on line 111 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\apache2\htdocs\doimp2.php on line 116 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\apache2\htdocs\doimp2.php on line 124 and when i got parts of it to work without errors it would execute both parts of my if loop to check for dups tally up the $rimp and $dup variables then insert it into the database anyway any help given would be much apreciated.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.