PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
OK, I am a newbie to PHP. I have been working on a website using WordPress and need to run a small script to generate registration codes for a website. The customer enters a number generated by the downloaded software onto this webpage:
and a registration number is supposed to be generated. The problem is the provider of the software has an ASP solution, but my server doesn't support ASP pages. I am trying to change the ASP code into PHP, but I have no experience in either of these languages. Any help would be great! Here is a link to the software providers explanation of what needs to happen:
Make sure you read the warnings on various pages about escaping any arguments before they're sent to the shell, otherwise you might end up finding half the server has been deleted!
Apologies if this next point is obvious, but this will only work if your server is a Windows platform because the executable KeyGen.exe will have been compiled to run on Windows machines. Assuming you are running Windows though, there shouldn't be any problem converting the ASP code to PHP - I think the PHP code would actually be quicker to write and simpler to understand.
Thanks for the quick response. I looked through the documentation you sent me and have it one step closer. The script is executing (no error), but I am having trouble with getting it to display the activation code generated. Here is what I have so far:
var WshShell = Server.CreateObject("WScript.Shell");
var oExec = WshShell.Exec(commandLine);
while( !oExec.StdOut.AtEndOfStream )
{
sActivationCode += oExec.StdOut.Read(1);
}
which I believe took the resulting code from the script, set it equal to "sActivationCode" and then the HTML code later displayed it. How can I accomplish this with PHP? Thanks again for the help, I really appreciate it.
OK, I fixed all that. "keygen" is a linux program provided to me by the company that wrote the software I am using. It takes a couple of variables, the long series of numbers is the unique product identifier for the software I will write, and sComputerCode is a code generated for their specific computer. They enter the computer code into the textbox on blindbidpro.com/register. All this gets inputted into keygen, then keygen is supposed to spit out a serial number for them to use in registering the product. Below is what I have already, but still no luck having it display the serial number. Thanks again for the help, I really appreciate it!
Remember that on UN*X-like systems in general, you don't always get a proper output when a command has been run, so you might need to consider this as a factor as well (IE do you need to pipe the output to a file, etc.)
Also, I can't see in your code where you're capturing the 'computer code' - you've got this line here:
but sComputerCode will be NULL because it hasn't been defined or contains any values, so you need to capture this value (either from the URL using $_GET or as a $_POST value.) It's possible that the keygen app isn't working properly because you haven't given it the second argument - though I would have expected some kind of error to happen, but then we are talking about Linux here
$sComputerCode = $_REQUEST['sCC'];
$sActivationCode = "";
// the path and the filename are case sensitive and keygen must be marked as executable on linux: chmod +x keygen
$commandLine = "/whatever/path/to/keygen 80311927548D0E53 $sComputerCode";
$sActivationCode = shell_exec($commandLine);
echo $sActivationCode;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.