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

    • ufukreis1212
      By ufukreis1212
      Hello, I am new members. Help me please. I want vbs convert to au3 .
      This vbs code : 
      'deneme Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem") strOSArch = GetObject("winmgmts:root\cimv2:Win32_OperatingSystem=@").OSArchitecture Set objNetwork = CreateObject("Wscript.Network") Set wshShell = CreateObject( "WScript.Shell" ) strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) Set oShell = WScript.CreateObject("WScript.Shell") proc_arch = oShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") Set oEnv = oShell.Environment("SYSTEM") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colMB = objWMIService.ExecQuery("Select * from Win32_BaseBoard") Set colCSes = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colProcessors = objWMIService.ExecQuery("Select * from Win32_Processor") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItemsx = objWMIService.ExecQuery( _ "SELECT * FROM Win32_VideoController",,48) '------------------------------------------------------------------- Set obj = GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory") i = 1 For Each obj2 In obj memTmp1 = obj2.capacity / 1024 / 1024 TotalRam = TotalRam + memTmp1 i = i +1 Next '-------------------------------------------------------------------- Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select Architecture from Win32_Processor") For Each objItem in colItems if objItem.Architecture = 0 then strArchitecture = "x86" end if if objItem.Architecture = 9 then strArchitecture = "x64" end if next '-------------------------------------------------------------------- strComputer = "." ' Local computer strMemory = "" i = 1 set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory") For Each objItem In colItems if strMemory <> "" then strMemory = strMemory & vbcrlf strMemory = strMemory & "Bank" & i & " : " & (objItem.Capacity /1024 /1024) & " Mb" i = i + 1 Next installedModules = i - 1 Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray") For Each objItem in colItems totalSlots = objItem.MemoryDevices Next '---------------------------------------------------------------------- Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" ) Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem" ) For Each objItem in colItems strComputerDomain = objItem.Domain Next for each System in SystemSet For Each objItem in colItemsx For Each objProcessor in colProcessors For Each bbType In colMB MbVendor = bbType.Manufacturer MbModel = bbType.Product MsgBox "İşletim Sistemi : " & System.Caption & vbNewLine & _ "İşletim Sistemi Versionu : " & + System.Version & vbNewLine & _ "Windows Mimari Yapısı: " & strOSArch & vbNewLine & _ "Kullanıcı isminiz: " & objNetwork.UserName & vbNewLine & _ "Bilgisayar ismi: " & strComputerName & vbNewLine & _ "Çalışma Grubu: " & strComputerDomain & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Anakart: " & MbVendor & " " & "[" & MbModel & "]" & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Grafik Kartı: " & objItem.Caption & vbNewLine & _ "Driver Version: " & objItem.DriverVersion & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "İşlemci Üreticisi: " & objProcessor.Manufacturer & vbNewLine & _ "İşlemci İsmi: " & objProcessor.Name & vbNewLine & _ "CPU Mimarisi: " & strArchitecture & vbNewLine & _ "İşlemci Çekirdek sayısı: " & oEnv("NUMBER_OF_PROCESSORS") & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Toplam RAM: " & TotalRam & " MB" & vbNewLine & _ "Toplam Slot: " & totalSlots & vbNewLine & _ "Boş Slot: " & (totalSlots - installedModules) & vbNewLine & _ "Ramlerin bulunduğu slotlar:" & vbcrlf & strMemory,0,"deneme" Next Next Next Next please help me , thanks.
    • JuanFelipe
      By JuanFelipe
       
      Hello friends, I have a query, it happens that I have a matrix nxn, the first column of this contains each cell a number with 21 digits, when I pass this matrix to Excel I obviously write that number as 1,10016E + 20, I solved it by adding a * at the end of each cell, but I want it to be written as a text so that I do not have to remove that *, I searched in Google but could not find an effective solution, thanks in advance. 
    • Puls3
      By Puls3
      Hi, This is my first post on the AutoIt Forums, I most of the time was able to get help from this community by merely searching though google and have been able to solve hundreds of problems this way, though in this case I was incapable of finding a solution to my problem. I am quite confident that it is a user error (And my fault) but I haven't been able to determine what I did wrong, any and all help would be greatly appreciated! I have uploaded my whole script pardon passwords to provide as much information as possible.
      I declared a global array at the top of the script and am having issues when I try to set it's value, and I fail to understand why.
      Error Message:
      "D:\Projects\AutoIt\Arena\Base.au3" (270) : ==> Subscript used on non-accessible variable.:
      $ExpMax[$i] = IniRead($TempSavePath, "Combatant" & $i, "ExpMax", $ExpMax[0])
      $ExpMax^ ERROR
      ConsoleWrite Log:
      Ran.
      Checking launch parameters.
      No launch parameters.
      Initiating load.
      Checking for save file.
      Save file not found.
      Load canceled.
      Loading or creating Combatant 1
      Base.au3
    • RamDemon
      By RamDemon
      Hi,
      Did anyone tried to  use Redis  with AutoIT as store DB ?
       Redis <-- more about it
      Mladen
×