Jump to content

Strahan

Members
  • Posts

    80
  • Joined

  • Last visited

Everything posted by Strahan

  1. Hi. I am writing a web app to control Zoom Player on my HTPC. I found that ZP supports listening on a TCP port to accept control commands. The docs say to quit ZP, send 5100,fnExit + ASCII 13/10 to port 4769. My original client was C# and I implemented it there, works great. I then realized WTF am I doing using an external .EXE to just send data to a TCP port? Switched to using PHP's fsockopen. Alas, that causes an error to pop up on ZP (List index out of bounds or some such). Perplexed, I wrote a GUI for the HTPC to just display an ASCII val breakdown of what it receives to compare: So it looks like they both send the data the same. Any idea why the discrepancy? Here is the code: C# that works: string cmdstr = ""; for (int x=2; x<=args.Length-1; x++) cmdstr += args[x] + " "; if (SendCommand(args[0], System.Convert.ToInt16(args[1]), cmdstr.Trim() + Environment.NewLine)) Console.WriteLine("Command string sent."); Environment.Exit(0); static bool SendCommand(string dest, int port, string cmd) { try { IPAddress[] ips = Dns.GetHostAddresses(dest); TcpClient client = new TcpClient(); IPEndPoint serverEndPoint = new IPEndPoint(ips[0], port); client.Connect(serverEndPoint); NetworkStream clientStream = client.GetStream(); ASCIIEncoding encoder = new ASCIIEncoding(); byte[] buffer = encoder.GetBytes(cmd); clientStream.Write(buffer, 0, buffer.Length); clientStream.Flush(); clientStream.Close(); clientStream.Dispose(); client.Close(); return true; } catch (Exception ex) { Console.WriteLine("Failed: " + ex.Message); return false; } } The PHP that is being difficult: send_data("lioth", "4769", "5100,fnExit"); function send_data($host,$port,$data='') { $fp = fsockopen($host,$port); if($fp) { fputs($fp, "$data\r\n"); fclose($fp); } return; }
  2. Thanks. I tried to mess around with the http_post_data method but it didn't like it. Your recommendation to use Google API worked good though. However, Google API is apparently quite a capable translator. Taking stuff from English -> German -> English resulted in pretty much the same text. Pretty cool (but unhelpful for me lol). I ended up making it go English -> German -> French -> Spanish -> Afrikaans -> Irish -> Swedish -> English to get the same funny effect as Babelfish hehe.
  3. Hi. My friend was amusing herself taking her emails, using Babelfish to translate them to other languages then translate them back to English and giggling at the weird wording. I figured I'd make it easier by writing a little page to do the legwork. I went to babelfish.altavista.com and viewed source. It seems the meat of the translation form is: <form action="http://babelfish.yahoo.com/translate_txt" method="POST" onSubmit="return verifyTrText();"; name="frmTrText"> <input type=hidden name="ei" value="UTF-8"> <input type=hidden name=doit value="done"> <input type=hidden name=fr value="bf-home"> <input type=hidden name=intl value="1"> <input type=hidden name=tt value="urltext" > <textarea rows="6" wrap=virtual cols="20" name="trtext""></textarea><br> <nobr><select name="lp" class="inp_sel" style="font-size:0.8em;"> <option value="">Select from and to languages</option> (... bunch of language opts stricken for size ...) </select></nobr> <input class="inp_btn" type="Submit" value="Translate" name="btnTrTxt"> </form> So to test I built a querystring based URL to try to translate "hello" to German: http://babelfish.yahoo.com/translate_txt?ei=UTF-8&doit=done&fr=bf-res&intl=1&tt=urltext&trtext=hello&lp=en_de Voila, worked great. Dug out the positioning in the file and wrote the code to get the foreign word then translate back to English. It works great for some stuff, but then it dies on others. I copied the foreign->english URL it made and found that if I paste it to Babelfish, I get nothing. Turns out if I remove the special chars in the string like %FC and stuff, it works fine. So apparently it's choking when trying to put the special accented stuff like umlauts in the querystring. Anyone know of a way to properly stick it in there, or is the problem on babelfish's side since they're expecting post data not get data? Does that even make a difference? Thanks My code: <?php if (empty($_REQUEST["text"])) { echo "<form name=data method=post action=trans.php>Language base:<select name=lang>"; echo "<option value='en_zh'>Chinese-simp</option>"; echo "<option value='en_zt'>Chinese-trad</option>"; echo "<option value='en_nl'>Dutch</option>"; echo "<option value='en_fr'>French</option>"; echo "<option value='en_de'>German</option>"; echo "<option value='en_el'>Greek</option>"; echo "<option value='en_it'>Italian</option>"; echo "<option value='en_ja'>Japanese</option>"; echo "<option value='en_ko'>Korean</option>"; echo "<option value='en_pt'>Portuguese</option>"; echo "<option value='en_ru'>Russian</option>"; echo "<option value='en_es'>Spanish</option>"; echo "</select><BR><HR><textarea name=text rows=5 cols=80></textarea><BR><BR>"; echo "<input type=submit value='Transmangle'>"; } else { $data = file_get_contents("http://babelfish.yahoo.com/translate_txt?ei=UTF-8&doit=done&fr=bf-res&intl=1&tt=urltext&trtext=" . str_replace(" ", "%20", $_REQUEST["text"]) . "&lp=" . $_REQUEST["lang"]); $foreign = substr(substr($data, strpos($data, "<div style=\"padding:0.6em;\">"), strpos($data, "<div style=\"padding:0.6em;\">")-strpos($data, "</div>")), strpos(substr($data, strpos($data, "<div style=\"padding:0.6em;\">"), strpos($data, "<div style=\"padding:0.6em;\">")-strpos($data, "</div>")), ">")+1, strpos(substr($data, strpos($data, "<div style=\"padding:0.6em;\">"), strpos($data, "<div style=\"padding:0.6em;\">")-strpos($data, "</div>")), "</div>")-(strpos(substr($data, strpos($data, "<div style=\"padding:0.6em;\">"), strpos($data, "<div style=\"padding:0.6em;\">")-strpos($data, "</div>")), ">")+1)); echo $foreign . "<BR>"; echo "http://babelfish.yahoo.com/translate_txt?ei=UTF-8&doit=done&fr=bf-res&intl=1&tt=urltext&trtext=" . urlencode($foreign) . "&lp=" . substr($_REQUEST["lang"], 3, 2) . "_en<BR><BR>"; $data = file_get_contents("http://babelfish.yahoo.com/translate_txt?ei=UTF-8&doit=done&fr=bf-res&intl=1&tt=urltext&trtext=" . str_replace(" ", "%20", $foreign) . "&lp=" . substr($_REQUEST["lang"], 3, 2) . "_en"); $english = substr(substr($data, strpos($data, "<div style=\"padding:0.6em;\">"), strpos($data, "<div style=\"padding:0.6em;\">")-strpos($data, "</div>")), strpos(substr($data, strpos($data, "<div style=\"padding:0.6em;\">"), strpos($data, "<div style=\"padding:0.6em;\">")-strpos($data, "</div>")), ">")+1, strpos(substr($data, strpos($data, "<div style=\"padding:0.6em;\">"), strpos($data, "<div style=\"padding:0.6em;\">")-strpos($data, "</div>")), "</div>")-(strpos(substr($data, strpos($data, "<div style=\"padding:0.6em;\">"), strpos($data, "<div style=\"padding:0.6em;\">")-strpos($data, "</div>")), ">")+1)); echo $english; } ?>
  4. This is aggravating the heck out of me. I made a web based checkbook so I can update it on the fly with my BlackBerry. The table has an "amount" field that I set to double. This is one record: Now when I go to do a select to find it by amount, I get this: Nothing. ??? Does this have something to do with having used double? I don't understand why it's failing to find it.
  5. *smacking myself* I can't believe I didn't think of that. Man I feel like an idiot newb Thanks!
  6. Hi. I have a database that catalogs my TV shows. I added the ability to mark various shows as being related to each other, like Cheers is linked to Frasier because of the shared character(s). I have a table for series groups with an auto inc int field for the index and a groupname text field. My problem comes with the group member list. It could be any amount of fields, from 2+ depending on how many shows are grouped together. My original plan was ten int fields "member1", "member2", etc etc but what if for some reason I want >10? My next thought was a text field "members" where I have a list of ints (the ints are the show info table index value) comma delimited. Problem with that is, if I have these records: gid = 1 members = "506;12;279;973;" gid = 2 members = "2318;28;1506;500;" Then when I want to do a lookup to see if show 506 is a member of a group I'd do "select groupname from seriesgrp where members like '%506;%'" then I'd get a match on both when it is not really correct to match on 2. What's the proper way to handle something like that? Thanks!
  7. Thanks, I'll take a look at it. I would certainly like to stop that refresh cycle, it is a bit of a kludge.
  8. Is that possible? I wrote a web version of the boardgame Wahoo. It has a blue background and refreshes every 5 seconds to see if a player did something. Looks great in Firefox, but when I fired up IE when it refreshes it shows a white background for a split second. Yea, it's not the end of the world but even that fraction of a second of white is annoying me hehe. Is there any way to make IE not do that? PS, and don't say convert the game to flash because while I would love to, I don't have the knowledge yet for that
  9. Hi. I want to read a website remotely via PHP. Problem is, it requires login. I can log in by opening the URL with the querystring setup to do a login, and that works but when I send the next query to get data it acts like I never logged in. I assume that's because it sets a cookie or something that isn't persisting. Is there any way around that? Thanks!
  10. Got a problem I'm trying to figure out. I'm looping through a security access control list. A user may match more than one ACL entry so as it goes if a user matches the current ACL entry, it adds to a $rights array the value of the entry (an int to be used in a bitwise AND to determine if the specific right is available). Now at the end I have the array $rights with a random amount of data in it. I want to return whatever value gives the most rights. What I want to do is something akin to return $rights[0] | $rights[1] | $rights[2]; I can easily loop on count($rights) and touch each ACL value, but since the | has to be stacked all at once I'm not sure how can I accomplish that. Any idea?
  11. Is it not possible to fire off an onmouseover event when you go over a visibility: hidden or display: none object? I can't get it to work. I can understand not working on a display: none because the object is technically not there, but hidden object still takes up its space on the page so I thought that space would be triggerable. Is it really not doable, or am I just screwing something up?
  12. Howdy. I have a database that has a list of "targets". Computer names, user names and IP addressing. If the current system that the script runs on matches the database for one of those targets, it runs that record. Now the computer & user names I have working fine. The IP I used to have working, but I hit a roadblock. I wanted to be able to do wildcards, like grab all IPs in specific subnets. I made it able to accept an IP like 192.168.0.* for example. However, I neglected to take into account small subnetted ranges.. like 192.168.1.192 with a CIDR of /28. That means only .192 - .207 would fall within that network. Soooo... I have fields like this in the database: 192.168.1.192/28 10.0.0.102/32 ..and the script knows that my current IP for example is 192.168.1.195. Short of looping through every single record that has an IP and testing it against my current IP, is there an efficient way to match an IP to a network designation like that?
  13. Whoo hoo, that did it! Thanks alot, ugh, I can't believe I was pounding my head against the wall for something as simple as getting my lefts and rights mixed up Thanks again!
  14. I have a table that I want to query for records that are not marked in another table. For example, this is the source table "chars": id [int, index] chartxt [text] Then there is the other table: "charused": uid [int, index] cid [int] user [int] A logged in user gets a numeric ID, say 123. I want to get a random record from the database, but one that hasn't been used yet. When the client uses a "character", it enters a record with the char ID into the charused table so I can keep track of what has been used and what hasn't. I was thinking select chartxt from chars right outer join charused on chars.id = charused.cid where charused.user is null order by rand() limit 1 So it would pull a record but only if the user is null in charused, meaning no record was found there. However, that doesn't seem to work. Any ideas? Thanks!
  15. Yea, I know * isn't valid for MySQL but it's not trying to be a MySQL wildcard. Lemme try to restate.. I have an script that runs on many boxes. It is supposed to take action based on what user is logged on and/or what the PC name is depending on how the admin user has it configured. There is a MySQL database it queries, and here is an example of the "target" table: [pcname] firewall filesrv game* printsrv So the field pcname has those data. The users are the ones who type in the PC names, and they are more comfortable/familiar with * as a wildcard which is why I use that. Since I can't think of any way that the wildcard already embedded in the data can be programatically relevant to MySQL itself in the query, I figured I'll let them use * if it makes them happy. If I run this script on a PC named "GAMEBOX01", I'll have a var $pc with that PC name string which I can easily see by looking at that example table that it matches the third record. My question is how do I do that in SQL? I can't just do select * from target where pcname like '$pc%' because that would stuff the full name in there. I can't do a substr of $pc because the position of the wildcard in the data won't be constant. So far, the solution I came up with that works is: $sql = "select * from target where pcname = '$pc' or "; for ($x=0; $x<=strlen($pc)-1; $x++) { $sql .= "pcname = '" . substr($pc, 0, $x) . "*'"; if ($x < strlen($pc)-1) $sql .= " OR "; } This does work, but it feels rather bulky and inefficient. I'm wondering if there is a better way. I'm hoping I'm just overlooking some easy way, hehe.
  16. Hi. I need help figuring out how to do a SQL SELECT. I have a login script running, and it has a variable $pc = the name of the PC. I have a MySQL database with a table "targets". It has a field, pcname. Mostly they are straight PC names, but I wanna include the ability to put in wildcards so one record may have pcname = 'GAMEBOX*'. I need to read the database and find any records where my $pc matches the pcname field. It's easy enough if I'm wildcarding the other way, I'd just do "where pcname like '$pc%'" or something but how would you do that the opposite? The only thing that came to mind was looping on the length of the $pc string and slowly building it out like if $pc = "gamebox01" it would query as g* ga* gam* game* etc. That seems horribly horribly inefficient, there must be a better way.
  17. Ooooh, that's perfect! Much much better than my hack job. Man I love this place Thanks alot!
  18. Sorry guys, my kid drug me away from the computer and I didn't have a chance to get back to it yet. As much as I love my coding, priorities are priorities What I need is the res of a video file, an MPG or AVI or such. I tried just leaving off the res and hoping the object autosizes, but alas that doesn't work. Interestingly with the code to play mpg if I specify it too large it does auto resize in the Y dimension, but not the X so I get a skewed aspect ratio. For the love of God, why did they make it nice in only one dimension?? Hehe. Thanks, and sorry again for the latent update.
  19. Thanks. Sorry but now that I reread the original post I see I wasn't very clear.. My setup is an album page where it shows thumbnails, then you click the thumbnail and get a detail page with a full size image and some other data. My problem isn't the actual page ranging per se, I have the page next/prev working on the album view, that was fairly easy as it is based on an arbitrary counter. However, my dilemma is record based - the prev/next once you are in the detail view. On the first page, the album view, it shows say 4 records like this: page 1: img src=img1 onclick=id.value='1092';submit(); img src=img2 onclick=id.value='1093';submit(); img src=img3 onclick=id.value='1102';submit(); img src=img4 onclick=id.value='1118';submit(); As you can see, ID isn't a straight increment it could skip so I can't just +/- the id code. So they click img2 and get the detail page with a pic that has id 1093. Prev button has to = 1092 to go back one, and next button has to = 1102 to go forward one. That's where my problem comes in, because on the detail page I have only an id number (index of the picture database) to go by, it's not being pulled in a set. Right now I'm doing: case "detail": // this is the start of the detail page. fold[id] is the index of the album so it can get all pics // request[id] is the picture index id of the image they clicked on the album view // $rs = $db->query("SELECT fileid FROM Media WHERE parent = {$fold["id"]} ORDER BY filename"); $grab = false; while ($row = $rs->fetch_assoc()) { if ($grab) { $next = $row["fileid"]; break; } if ($row["fileid"] == $_REQUEST["id"]) { @$prev = $tmp; $grab = true;} $tmp = $row["fileid"]; } $rs->free(); Which works, but strikes me as kinda "kludgy" hehe.
  20. Hello! I have some video files I want to embed in a website. Problem is, I don't know the resolutions. If I don't pass res to the object for video, it makes it a real small window with the controls off screen so I need to find the res. Is there any way to do that?
  21. I am building a photo gallery page, and I'm using limit to do paging. Right now I do something like: select id,filename from photos where album = 2 order by filename limit 1,16 Which works great. Now when you click the photo, I want a "prev" and "next" button to move between individual photos. Prev doesn't strike me as very hard, on the album view I can have it store the current id in a var then for the next photo, have it pass that id as "prev". However next is where I'm not sure the most efficient way to proceed. My plan right now is to just select all records from the album and scroll through them until I find the current id then capture that way, but it seems horribly inefficient. What's the best way then to grab the neighboring records?
  22. Ahh, that was the problem. I downloaded that 5.2.6 ZIP and it resolved my issues. Well, sorta. Once I overwrote the ext folder with the DLLs I downloaded, all of them started to work -except- mysqli, pretty much opposite of the old behavior heh. I renamed the new mysqli dll to dll_new and copied back in the older one and then it worked. Weird. The mysqli API library version in phpinfo says "mysqlnd 5.0.1-beta - 070402 - $Revision: 321 $". Well, as long as it works that's good anyway hehe. Thanks for the help!
  23. Howdy. I have PHP 5.2.6 running under Windows 2003. I wanted to be able to talk to MySQL so I added the php_mysqli extension. It works great. I now wanted to be able to manipulate images, so I added php_gd2 but whenever I do var_dump(gd_info()); I get "Fatal error: Call to undefined function gd_info()". After fighting with it for awhile, I installed php_snmp and tried querying SNMP on my APC SmartUPS and that also returns undefined function when I use snmpget so apparently my PHP is ignoring my extensions. Weird thing is, the mysqli works fine. This is my php.ini's relevant section: extension_dir = "d:\apps\php\ext" extension=php_gd2.dll ;extension=php_mysqli.dll ;extension=php_mbstring.dll extension=php_exif.dll extension=php_snmp.dll The folder specified in the _dir is accurate, that's where the DLLs are. I remarked out the mysql stuff just to test something. I've restarted IIS every time I made a change. Heck, I even tried restarting the server itself to no avail. Any ideas what I should be checking? Thanks! PS, I did phpinfo and it shows a mysqli section but no mention of gd2, exif, mbstring, or snmp.
  24. I need SFN for a legacy app that gets pissy with spaces. Thanks for the com suggestion thorpe, that worked like a champ!
×
×
  • 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.