Jump to content
Sign in to follow this  
JohanV

Convert PHP to AutoIT

Recommended Posts

JohanV

Hello,

I've created a script for a Bingo / Lottery kind of game in PHP.

Now I want to make this a standalone application in AutoIT.

I really dont know how to do that as i´m just a Autoit-beginner.

Can you help me with it?

In general I have the following files:

data.csv - the "database" where the bingo-numbers are stored, together with the name of the candidate

index.htm - to show the 'program' in a browser

input.php - to take care of input

results.php - to show the winners

numbers.txt - the winning numbers to compare with

I have the following files:

Input.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {  font-family:Times New Roman, Verdana,Geneva; font-size:12px; color:#000000;
    margin-left:20px; background:#F7F5DF; width: 300px; }
H2 { font-family:Times New Roman, Geneva; font-size:16pt; color:#840018; text-align:center; }
</style>
<link rel=stylesheet href="style.css" TYPE="text/css">
<title>Input</title>
<?php
$sepsign   = '/;/';
$text     = '';
$wnumbers = '';
$counter    = 0;
$filed     = "data.csv";
$fileg     = "numbers.txt";
$in_numbers = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $name = $_POST['name'];
  $in_numbers = $_POST['$in_numbers'];
}

$fd        = fopen($fileg,"r") or die ("Unable to open $file.");
$text     = fread($fd,filesize($fileg));
$wnumbers = preg_split($sepsign,$text); // wnumbers is an array with winning numbers
Fclose($fd);

for ($j = 0; $j < 10; $j++) {
   for ($i = 0; $i < 10; $i++) {
      if ($wnumbers[$i] == $in_numbers[$j])  { $counter++; }
   }
}   // $counter will contain the number of matches on the input

# Append and write the line in a file <number of matches>;<name>;<number 1>;<number 2>; etc

$fdb = fopen($filed,"a+");
fwrite($fdb,$counter . ";" . $name);
for ($i = 0; $i < 10; $i++) {
   fwrite($fdb,";" . $in_numbers[$i]);
}
fwrite($fdb,"\r\n");
fclose($fdb); 
?>
<h2><br>Your input has been stored successfully!</h2>
</body></html>

Results.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML><head>
<meta http-equiv="Content-Type" content="text/HTML; charset=iso-8859-1">
<style>
body {  font-family:Times New Roman, Verdana,Geneva; font-size:12px; color:#000000;
    margin-left:20px; background:#F7F5DF; width: 300px; }
H2 { font-family:Times New Roman, Geneva; font-size:16pt; color:#840018; text-align:center; }
</style>
<title>Result</title>
</head><BODY>
<h2>Result of the draw</h2><hr><br>
<?php
$sepsign   = '/;/';
$text     = '';
$filed     = "data.csv";
$fileg     = "numbers.txt";

$fd = fopen($filed,"r") or die ("unable to open $file.");
$text = fread($fd,filesize($filed));
$lines = preg_split("/\r\n/",$text);    // Will split the file data.csv in lines
$count_reg = count($lines);
fclose($fd);
sort ($lines);
reset($lines);

for ($i = ($count_reg - 1); $i>($count_reg-4); $i--) {  // The three highest scores are showed
   $collums = preg_split($sepsign,$lines[$i]);
   print "<b>Name: " . $collums[1] . "<br>";
   print "Number of matches: " . $collums[0] . "</b><br>";
   print "Input: ";
   for ($j = 2; $j < 12; $j++) {
     print $collums[$j];
     if ($j <> 11 ) { print ", "; }  // to prevent the "," to appear after the last number
   }
   print "<br><br>";
}
$fd    = fopen($fileg,"r") or die ("Unable to open $file.");
$text = fread($fd,filesize($fileg));
$wnumbers = preg_split($sepsign,$text);
Fclose($fd);

print "<br><b>Bingo numbers</b><br><hr>";
for ($j = 0; $j < 11; $j++) {
   print $wnumbers[$j];
   if ($j < 9 ) { print ", "; }  // to prevent the "," to appear after the last number 
}
?>
</body></html>

Index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {  font-family:Times New Roman, Verdana,Geneva; font-size:12px; color:#000000;
    margin-left:20px; background:#F7F5DF; width: 300px; }
H2 { font-family:Times New Roman, Geneva; font-size:16pt; color:#840018; text-align:center; }
</style>
<title>Bingo game, input numbers.</title>
</head><body>
<form action="input.php" method="post" name="form">
<center>
<h2>Input numbers</h2>
lines  &nbsp; <input type="text" name="lines" size=20 maxlength=50><br><br>
Number &nbsp;1 &nbsp;<input type="text" name="$in_numbers[0]" size=4><br>
Number &nbsp;2 &nbsp;<input type="text" name="$in_numbers[1]" size=4><br>
Number &nbsp;3 &nbsp;<input type="text" name="$in_numbers[2]" size=4><br>
Number &nbsp;4 &nbsp;<input type="text" name="$in_numbers[3]" size=4><br>
Number &nbsp;5 &nbsp;<input type="text" name="$in_numbers[4]" size=4><br>
Number &nbsp;6 &nbsp;<input type="text" name="$in_numbers[5]" size=4><br>
Number &nbsp;7 &nbsp;<input type="text" name="$in_numbers[6]" size=4><br>
Number &nbsp;8 &nbsp;<input type="text" name="$in_numbers[7]" size=4><br>
Number &nbsp;9 &nbsp;<input type="text" name="$in_numbers[8]" size=4><br>
Number 10&nbsp;<input type="text" name="$in_numbers[9]" size=4><br><br>
<input type="submit" value="Submit..."></FORM>
</center>
<p />&nbsp;<p />
</body></html>

Share this post


Link to post
Share on other sites
nullschritt

Hello friend! Welcome to autoit. While I don't have the time currently to write an example code for you, I can make some reccomendations which you can look up in the help file.

Depending on if you want the app to work offline, there's two different options I see that you have

The first option is to simply embed the webpage into a gui. (create a GUI then use _IECreateEmbedded) This will allow anyone with an internet connection to access the game.

If you don't wish to require an active internet connection, you can start your job by looking up the following information.

1)To store data (data.cvs and numbers.txt) it's reccomended you use SQLite [_SQLite_Open()], although INI files may work, depending on how much data you plan to store [iniwrite()].

2)Use a InputBox() to request input from the user

3)Process the information the same way you did with php.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • nooneclose
      By nooneclose
      I want to check some Excel data against data on a website in Chrome. I use Chrome because the site I use does not function properly in Internet Explorer or Firefox. I know how to do the Excel stuff I just can not figure out how to send to Chrome, let alone check to see if the data matches or not. I am also having trouble finding any help online while searching for Chrome functions for Autoit. I have a Chrome UDF installed but I still can not figure out how to get my code to properly function. (I am not posting code because I am  sure my code isn't right, to begin with)
      As usual, any and all help would be greatly appreciated. 
    • ohaya
      By ohaya
      Hi,
      I have a situation where I need to make one request to get a kind of pre-logon page, then click a link on that pre-logon page, which then returns a login form page, and then fill in information in the form page and submit it.
      How can I handle that using AutoIT?
      I can get the AutoIT script to tab to the link, then send an ENTER, which then causes the FORM page to appear in IE.  However, I cannot seem to get the form object from the FORM page (_IEFormGetObjByName fails when it searches for the form).  Why is that, and how can I get the AutoIT to process the FORM page?
      Thanks,
      Jim
    • TheSaint
      By TheSaint
      Here is a simple program that some of you might appreciate.
      It is a more full fleshed out version of something I worked on a while back as a proof of concept.
      I will just quote the information found in the Program Information dialog.

      INItoSQL DB.zip
      INItoSQL DB v1.1.zip  (see Post #3 for update details)
      Program requires the sqlite3.dll, not included, but easily enough obtained.
      I have also included the beginnings of a new UDF (SimpleSQL_UDF) I am working, which you can use with the included 'Check conversion.au3' file to check a resulting conversion ... just modify the values for a few variables to suit your situation.
      I've not yet gotten around to coding a testing/checking results script, so I recommend the following open source program, which I have been using for some time. It was here, but is now here at GitHub - DB Browser for SQLite
    • JuanFelipe
      By JuanFelipe
      Hello friends, I have a simple question, can I have a variable that is not reset, even if my program is closed?
      That is, I want to make a program that can only be opened once, have a variable $ ini = 0, when it is opened for the first and only time it becomes $ ini = 1, so that it can not use the program a second time, as if it was a test software.
      I do not want the variable to depend on a reading of an external file that is easily manipulated. Thank you.
    • TheSaint
      By TheSaint
      Here is the bare bones of a UDF I have started work on.
      Mostly just a proof of concept at this stage, and still need to add some functions and dress the UDF up a bit ... to look like a UDF ... though it has my own distinct styling, especially as I have never really developed a UDF before now .... used plenty and modified plenty though. I've even invented my own UDF variable naming convention, which I am sure some of you will be aghast at. I work with what feels best for me, but others are free to adapt if they wish.
      The idea is to emulate the simplicity of INI files, but gain the benefits of SQL.
      Two scripts are provided.
      (1) The UDF, a work in progress - SimpleSQL_UDF.au3
      (2) An example or testing script - UDF_Test.au3
      Another first for me, is creating a 2D array from scratch, never done that before, that I can recall ... never had a need, and even for 1 dimension arrays, for a long time now, I have just used _StringSplit to create them. So I needed a bit of a refresher course, which my good buddy @TheDcoder assisted me with ... not without some angst I might add. LOL
      SimpleSQL_UDF.zip
      Program requires the sqlite3.dll, not included, but easily enough obtained.
      Hopefully the usage is self-evident ... just change the Job number variable in the UDF_Test.au3 file to check the existing functions out.
      Enjoy!
      P.S. This is also related to a new program I have just finished and uploaded - INItoSQL DB
×