dfwcomputer Posted December 22, 2006 Share Posted December 22, 2006 Hi,I have searched your forum for reading and searching text files, but can't find a relevant post......what i would like to do is have a form that you could input a string of some sort and it would search a text file (maybe even 2 or 3 text files if possible) and display the result.e.gwe have a game server that keeps a log of gamers that play on our server........i have 3 text files (can be put into one if need be) of major organizations that log cheaters.so each of these files is full of known cheaters.e.g.organization1.txtorganization2.txtorganization3.txtand the text file would look like[1969.12.31 18:00:00] 227dbb4781b5d308d654b257ebc98dea "Bongas_Rachu" "??" ACI-MEM-INJECTIONIn the above the [b]"227dbb4781b5d308d654b257ebc98dea"[/b] is the GUID and the [b]"Bongas_Rachu"[/b] is the User Name.when i want to check somebody (e.g. for a background check or whatever) i can open the Form and input either a GUID or username and have it display the results if they are in the text files.here is a picture of what the form might look like. to give you a better understanding[img]http://farm1.static.flickr.com/127/329620718_86aad1d257_o.jpg[/img]is this possible using php.And any ideas on where to start.......Thanks, Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2006 Share Posted December 22, 2006 This should get you a good start.[code]<?php function ischeater($search,$type) { switch ($type) { case 'guid': $pos = 2; break; case 'uname': $pos = 3; break; case 'ip': $pos = 4; break; } $lines = file('organization1.txt'); foreach ($lines as $line) { $tmp = str_replace('"','',$tmp); $tmp = explode(' ',$line); if ($tmp[$pos] == $search) { return true; } } return false; }?>[/code] Quote Link to comment Share on other sites More sharing options...
dfwcomputer Posted December 22, 2006 Author Share Posted December 22, 2006 thanks for the reply.......but i'm a bit of a noob.......i played around but not real sure how to set it up.Any ideas would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2006 Share Posted December 22, 2006 C'mon that salmost a complete example!All you would need do is pass it a username for instance, and tell it you want to search via guid. eg;[code=php:0]if (ischeater('thorpe','guid')) { echo "thorpe is a cheater";} else { echo "thorpe is honest to goodness!";}[/code]Now all you really need do is make your form (nothing to do with php) and have it submit to a page where this function is.If you can't get something sorted from that as an example, you really need to do a 101 in php basics first. Don't try to run before you can walk. Quote Link to comment Share on other sites More sharing options...
dfwcomputer Posted December 22, 2006 Author Share Posted December 22, 2006 sorry m8....i'm totally new to all this.......i'm just starting out.....so if i create a forme.g.[code]<form id="form1" name="form1" method="post" action="index.php"> <label>Search <input type="text" name="textfield" /> <select name="select"> <option>guid</option> <option>uname</option> <option>ip</option> </select> </label> <label> <input type="submit" name="Submit" value="Submit" /> </label></form>[/code]and in the same directory have the index.php file and the organization1.txt file.....is this correct Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2006 Share Posted December 22, 2006 Yes. Then place the function in index.php along with the following code.[code=php:0]if (isset($_POST['Submit'])) { if (ischeater($_POST['textfield'],$_POST['select'])) { echo $_POST['textfiled']." is a cheater"; }}[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2006 Share Posted December 22, 2006 If you want it to work with more than one text file, modify this...[code=php:0]$lines = file('organization1.txt');foreach ($lines as $line) { $tmp = str_replace('"','',$tmp); $tmp = explode(' ',$line); if ($tmp[$pos] == $search) { return true; }}[/code]to be...[code=php:0]$files = array('organization1.txt','organization2.txt','organization3.txt');foreach ($files as $file) { $lines = file($file); foreach ($lines as $line) { $tmp = str_replace('"','',$tmp); $tmp = explode(' ',$line); if ($tmp[$pos] == $search) { return true; } }}[/code] Quote Link to comment Share on other sites More sharing options...
dfwcomputer Posted December 22, 2006 Author Share Posted December 22, 2006 thanks much appreciated............to add other text files would i just add e.g.[code]$lines = file('organization1.txt');$lines = file('organization1.txt');$lines = file('organization2.txt');$lines = file('organization3.txt');[/code]Beat me to it.......loland is it simple to display the line in the text file as well.....or to difficult....thankyou Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2006 Share Posted December 22, 2006 You could. In the function change...[code=php:0]return true;[/code]to...[code=php:0]return $tmp;[/code]Then, change the other code to....[code=php:0]f (isset($_POST['Submit'])) { if ($line = ischeater($_POST['textfield'],$_POST['select'])) { echo $_POST['textfiled']." is a cheater. "; echo $line; }}[/code] Quote Link to comment Share on other sites More sharing options...
dfwcomputer Posted December 22, 2006 Author Share Posted December 22, 2006 yes it worked perfectly.....then i did the last edit and it comes up with[code]0b25e10da12e1811dbffbda36e1369c1 is a cheater. Array[/code]thanks Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2006 Share Posted December 22, 2006 Sorry, you'll need to change this...[code=php:0]$tmp = str_replace('"','',$tmp);[/code]to...[code=php:0]$line = str_replace('"','',$line);[/code]it had another error anyway.Then you'll need....[code=php:0]return $line;[/code] Quote Link to comment Share on other sites More sharing options...
dfwcomputer Posted December 22, 2006 Author Share Posted December 22, 2006 thankyou it is greatly appreciated Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.