Jump to content

konnwat

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Everything posted by konnwat

  1. Well i have 2 tables. table1 has `datetime` `name` `language` `points` `group` `rank` table2 has `position` `name` `rank` `points` `group` I need to copy the first one over to the second one and the position is based on the points. I thought the best way was to use... INSERT INTO table2 (position, name, rank, points, group) SELECT (0, name, rank, points, group) ORDER BY DESC But table1 has some duplicates of `name`. I need to be able to copy the table with no duplicates so i thought about making the column Unique but i dont know how i would go about doing that for a text column. Also I thought the position could be done by Auto Increasement but then everytime the table updates i need to set the default position back to 1 and i dont know how to do that either. (I thought if i set the default to 1 and Truncate the table it might work but i havent tried) Can anyone help me? Thanks
  2. hehe i was going to say through a session but i was beaten too it xD <?php session_start(); $_SESSION['key'] = 'value'; //in the other php file you can put session_start(); $var = $_SESSION['key']; ?>
  3. Hey i made a nice bot that opens a socket, gets some html, parses it and adds the information to a db. but... the site now needs you to be logged in to view the source! so how would i go about making it log in? :-\ i was thinking sending some headers to the socket that has the session cookie in them but i dont know how i would do that :-X here is my code... <?php $fp = fsockopen("www.barafranca.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET /compress.php?r=stats.inc HTTP/1.1\r\n"; $out .= "Host: barafranca.com\r\n"; $out .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204\r\n"; $out .= "Connection: Close\r\n\r\n"; $file = ''; fwrite($fp, $out); while (!feof($fp)) { $file .= fgets($fp, 128); } fclose($fp); } ?>
  4. <?php $var = 1*$var; ?> quite simple just do some maths with a string and if its a number it will turn into a float/int
  5. Im confused. I've got a 10 png images, with aplha, of the numbers 0-9 they all have the same hight but not the same width. I got a mysql database with a counter number and i made a counter works fine, but its not in aplha :s heres my code... <?php //str_split if(!function_exists('str_split')){ function str_split($string,$split_length=1){ $count = strlen($string); if($split_length < 1){ return false; } elseif($split_length > $count){ return array($string); } else { $num = (int)ceil($count/$split_length); $ret = array(); for($i=0;$i<$num;$i++){ $ret[] = substr($string,$i*$split_length,$split_length); } return $ret; } } } //connect to mysql $mysqlLink = mysql_connect(----------------); mysql_select_db(--------------); //get id if(isset($_GET['id'])) { $id = $_GET['id']; } else { $id = '1'; } //get count number and +1 $result = mysql_query("SELECT * FROM counters WHERE ID=".$id); $rows = mysql_fetch_array($result); $count = $rows['Count']; if ($_COOKIE[$id] != 'done') { $count++; mysql_query("UPDATE counters SET Count = '$count' WHERE ID=".$id); //set cookie setcookie($id, 'done', time()+60); } //split the count $numbers = str_split($count); $digits = count($numbers); $nextwidth = 0; //make image header ("Content-type: image/png"); for($i=0; $i<$digits; $i++) { list($width, $height, $type, $attr) = getimagesize("numbers/{$rows['Type']}/{$numbers[$i]}.png"); $nextwidth += $width; } $im = imagecreate($nextwidth, $height); imagesavealpha($im, true); $nextwidth = 0; imagecolorallocate($im, 0, 0, 0); for($i=0; $i<$digits; $i++) { list($width, $height, $type, $attr) = getimagesize("numbers/{$rows['Type']}/{$numbers[$i]}.png"); $image[$i] = imagecreatefrompng("numbers/{$rows['Type']}/{$numbers[$i]}.png"); imagesavealpha($image[$i], true); imagecopymerge($im,$image[$i], $nextwidth, 0, 0, 0, $width, $height, 100); $nextwidth += $width; } imagesavealpha($im, true); imagepng($im); ?> i have imagesavealpha($im, true); in 3 times, i tried it everywhere :s please help thanks
  6. why don't you try making one :P when you log on to program, write to a txt file or a MySQL database that your on and then [code]<?php $online = file_get_contents(''data.txt"); if($online = "yes") {     echo "Live chat!"; } ?>[/code] and use a java IRC client for help :P well its free ^^
  7. [code]<?php try { eval('will cause error'); } catch (Exception $e) {   echo 'Caught exception: '.$e->getMessage()."\n"; } ?>[/code] try that ^^
  8. okay i got it,it seems for no reason my bot runs the whole script again and again every now and then :P this is my connect code. [code] <?php set_time_limit(0); //set vars $host = 'irc.barafranca.com'; $port = '6667'; $nickname = "Bot"; $channel = file('../bot/channels.txt'); //open data.txt and botlines.txt $cokehandle = fopen('../coke/data.txt', w); $lineshandle = fopen('../botlines.txt', a); fwrite($lineshandle, "\n\n\n"); $killmode['#chan'] = 'on'; $ks = array(); //connect to IRC $socket = fsockopen($host, $port); stream_set_timeout($socket, 60*60*24*365); fwrite($socket, "NICK ".$nickname."\r\n"); fwrite($socket, "USER ".$nickname." 8 * :Nick's Bot\r\n"); fwrite($socket, "MODE ".$nickname." +B\r\n"); while ($line=fgets($socket)) {   if (strpos($line, "433")>0) die();   if (strpos($line, "004")>0) {       $chancount = count($channel);       fwrite($socket, "PRIVMSG nickserv :IDENTIFY Bot hello123\r\n");       for ($i = 0; $i < $chancount; $i++) {             fwrite($socket, "JOIN ".$channel[$i]."\r\n");       }       break;   } } ?>[/code] there is a [color=blue]$lineshandle[/color]  to log my lines and there are a lot of random "\n\n\n" in the middle of all the lines. this must mean that my whole php script just randomly starts again after a while :s and some times is give me an EOF because it doent run again, it just ends :P how do i stop this?
  9. yeah i started posting that post and then the forum said someone else had posted but i didn't go back and read what you said so i just posted. sorry bout that ;)
  10. its the servertime and it must have been retrieved with the time() function try [URL=http://uk.php.net/time]http://uk.php.net/time[/URL]
  11. change file() to file_get_contents() that returns it all in one string instead on an array per line.
  12. [quote author=SharkBait link=topic=123057.msg508762#msg508762 date=1169235895] Are you able to output or log the incomming server text? Perhaps it will tell you why you're the bot is timing out? I haven't used php sockets but I have done my own IRC Client with VB.NEt and I can toggle on/off the parsing of the IRC server text.  Sometimes it can give you clues as to why you connection drops/timesout. [/quote] yes i can, i said this in a previous post. there seems to be no common link of why my bot is leaving.
  13. NICE, thats gotta work, thanks ^^
  14. [url=http://info-x.co.uk/fp_8706.asp]http://info-x.co.uk/fp_8706.asp[/url] says that it works :O
  15. i downloaded it off a website, maybe theres a script before it the counteracts it but i cant see one, its just the while loop.
  16. to be honest, neither do I :D but it does, since i realised it doesn't look right i thought i gotta change it and everytime i did it went mental :s
  17. I like the sound of the "server stop spitting lines" that sounds true. thank you :D, how can i stop this? theres no errors in my ping script by the way, every time i change it from what it was the bot leaves with a ping time out. but its i have it like it was original it leaves with EOF. and also my server is made for php bots, no safe mode, fsockopen is allowed, and i posted a ticket about CPU usage before and the admins didn't seem to ban me for it ^^
  18. do you (or anyone) know why the fgets($socket) has gone? this usually means there is some kind of error in my scripts. but it cant be fatal because then it doesn't connect at all stange :P
  19. i got an IRC bot that when you type !hof it brings up the hall of fame. one problem with the hall of fame is if two people have the same "ks" (killing skill) then it only shows one on the hof. heres my code. [code] <?PHP if (stripos($line, ":!hof")>0) { $hof = ''; $ksreverse = array_flip($ks); $hofnum = 0;     for ($i=100; $i>0; $i--) { if (isset($ksreverse[$i])) {     $hof[$hofnum] = $ksreverse[$i];     $hofnum++;     if ($hofnum == 3) { break;     } }     }     fwrite($socket, "PRIVMSG $chan :Hall of Fame: 1st - ".ucwords($hof[0])." || 2nd - ".ucwords($hof[1])." || 3rd - ".ucwords($hof[2])."\r\n"); } ?>[/code] I tried this one too find if the array has two keys with the same value but theres an error. [code] <?PHP if (stripos($line, ":!hof")>0) { $hof = ''; $ksreverse = array_flip($ks); $hofnum = 0;     for ($i=100; $i>0; $i--) { if (isset($ksreverse[$i])) {     $hof[$hofnum] = $ksreverse[$i];     $hofnum++;     if ($hofnum == 3) { break;     } }     }     $samekscount = array_count_values($ks);     $ksnicks = array_keys($ks);     for ($i=0; $i<3; $i) {         if($samekscount[$ks[$hof[$i]]] > 0) {             for ($ii=0; $ii<count($ksnicks); $ii++) {                 if($ks[$ksnicks[$ii]] == $samekscount[$ks[$hof[$i]]])                     if(isset($newhof[$i])) {                         $newhof[$i+1] = $ksnicks[$ii];                     } else {                         $newhof[$i] = $ksnicks[$ii];                     }                 }             }         }     }     if(isset($newhof[0])) {         $hof[0] = $newhof[0];     }     if(isset($newhof[1])) {         $hof[1] = $newhof[1];     }     if(isset($newhof[2])) {         $hof[2] = $newhof[2];     }     fwrite($socket, "PRIVMSG $chan :Hall of Fame: 1st - ".ucwords($hof[0])." || 2nd - ".ucwords($hof[1])." || 3rd - ".ucwords($hof[2])."\r\n"); } ?>[/code] please help, is there any way of asking php to search an array for ALL keys with a certain value?
  20. right so would that mean, the while($line=fgets($socket)) was somehow broken. so fgets($socket) is no more???
  21. If it helps anyone, when my bot leaves for no reason, its says: "EOF from client" don't know what the means ^^
  22. yeah i checked it all nothing wrong with it, no unknown chars before # or anything :(
  23. hhmmmm, never seen that one before ^^ might be a setting in your php.ini file that stops you viewing files not on your own server. someone else will need to help you there
  24. [23:48] IgBot joined the chat room. [23:48] IgBot was promoted to operator by ChanServ. [23:56] IgBot left the chat room. (Ping timeout: 241 seconds) no that broke it :P [code] <?PHP //pong at pings if (strpos($line,"PING :") != 0) { fwrite($socket, "PONG :irc.barafranca.com\r\n"); } ?>[/code]
×
×
  • 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.