Jump to content

[SOLVED] Search Text File Via Form | Display Results


dfwcomputer

Recommended Posts

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.g

we 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.txt
organization2.txt
organization3.txt

and the text file would look like

[1969.12.31 18:00:00] 227dbb4781b5d308d654b257ebc98dea "Bongas_Rachu" "??" ACI-MEM-INJECTION

In 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,

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]
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.
sorry m8....i'm totally new to all this.......i'm just starting out.....

so if i create a form

e.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


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]
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.......lol

and is it simple to display the line in the text file as well.....or to difficult....

thankyou
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.