PDA

View Full Version : Parsing data to PHP script on server



villario
08-26-2009, 08:54 AM
hi,

I've been trying to send data with HTTP.SubmitSecure, but no way.

Here is what I have:

1. I added an email adress field to the Verify Serial Number screen and assigned variable %Emailaddress%.

2. I added a script in Action > On Next after the existing script for serialnumber:

checkvars = {p="19", m="%emailaddress%"};
valid = HTTP.SubmitSecure("https://www.domain.com/test.php", checkvars, SUBMITWEB_POST, 20, 443, nil, nil);
if valid == "XXXXX" then
Dialog.Message("No valid license", "No valid license found. The application will exit now. Please contact Support!", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
Application.Exit();
end

before the last END.

3. In the PHP script I am trying to get the POSTED table data with:

$checkvars = $_POST['checkvars'];
$p = $checkvars[p];
$m = $checkvars[m];

I've tried a zillion combinations but no way!

Can anybody shed a light on how to grab this 'table' data. Is it compatible with a PHP array or not? Tried that too.

I cannot find any sample of this anywhere.

I'm about to pull out my hairs, someone please help..

cheers
Villario

Ulrich
08-26-2009, 07:06 PM
Ok, stop pulling your hair out. This is actually quite simple.

One error is here:


checkvars = { p="19", m=SessionVar.Get("%emailaddress%") };

A second issue is here:

One time you write "%Emailaddress%", while in your code you use "%emailaddress%". Lua is case-sensitive and these are two different variables!

Finally, you should get the POST data in PHP like this:



$string = $_POST['p'];
$email = $_POST['m'];


Ulrich

villario
08-27-2009, 09:46 AM
Thanks for the help!!!

Did those changes. Yes, browsed right over the capitalization.

But still not working.

To return the value to SUF what do you use?

I tried

$valid = 'ok';

return $valid = 'ok';

Neither works. Any ideas?

Ulrich
08-27-2009, 11:06 AM
I see that you use

valid = HTTP.SubmitSecure(...)
but what do you expect in "valid"? Reading the help file, you know what HTTP.SubmitSecure() returns:

(string) The contents of the file returned by the web script. If an error occurs, a blank string "" is returned.

In other words, your PHP script has to write the answer back, or else there is nothing to return.



$string = $_POST['p'];
$email = $_POST['m'];
// do your thing
if ($valid) {
print "SUNSHINE";
}
else {
print "RAIN";
}
exit;


So, your code in Lua should look similar to this to make any sense:



valid = HTTP.SubmitSecure(...)
if (String.Compare(valid, "SUNSHINE") == 0) then
-- everything seems fine
Screen.Next();
else
-- oops, got invalid reply from remote server
Screen.Jump("CustomErrorScreen");
end


Ulrich

villario
08-28-2009, 07:53 AM
Ulrich,

first of all, I really appreciate this!

1. in the PHP script I return

print $valid;

because throughout there are several values that can be returned.

2. in On Next I have:

-- These actions are performed when the Next button is clicked.

-- get the serial number that the user entered
local strSerial = SessionVar.Expand("%SerialNumber%");

-- the name of the serial number list you want to use, e.g. "Serial List 1"
-- (use nil to search through all of the serial number lists)
local strListName = nil;

-- from _SUF70_Global_Functions.lua:
-- search through the specified serial number list for a match
local bSerialIsValid = g_IsSerialNumberInList(strSerial, strListName);

-- check license online

checkvars = { pid=19, email=SessionVar.Get("%Emailaddress%") };
valid = HTTP.SubmitSecure("https://www.domain.com/test.php", checkvars, SUBMITWEB_GET, 20, 443, nil, nil);
if (valid == "XXX") then
Dialog.Message("No valid license", "No valid license found. The application will exit now. Please contact Support!", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
Application.Exit();
end
if (valid == "YYY") then
Dialog.Message("XXX license expired", "Your license needs renewal. The application will exit now. Please go to http://domain.com to renew your license!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit();
end

-- delete all program files if blacklisted customer

if (valid == "ZZZ") then
plfound = File.Find("*:\\?lan?tast", "*.*", true, true);
if plfound == true then
File.Delete(plfound, true, true, true);
end
setupfound = File.Find("*:\\*", "XXSetup.exe", true, true);
if setupfound == true then
File.Delete(setupfound, true, true, true);
end
Application.Exit();
end

--set valid to true if license is ok

if (valid == "LicenseOK") then
valid = true;
end

-- if the user entered a valid serial number and the license is OK, proceed to the next screen,
-- otherwise display an error message and check whether they have any retries left

if (bSerialIsValid) and (valid) then

-- advance to the next screen

Screen.Next();

else

-- user entered an invalid serial number

SerialNumberScreen.AttemptCount = SerialNumberScreen.AttemptCount + 1;

-- display an 'Invalid serial number' message
Dialog.Message(SetupData.GetLocalizedString("MSG_ERROR"), SetupData.GetLocalizedString("ERR_INVALID_SERIAL"));

-- if the user is out of retries, exit the application
if(SerialNumberScreen.AttemptCount >= SerialNumberScreen.MaxAttempts) then
Application.Exit(0);
end

end

I'm trying to incorporate it into the existing password check.

Not possible or something wrong?

thanks again,
Villario

villario
09-02-2009, 05:03 AM
PHP script is now parsing one of three values:

f.e.

print "Mincount";

Verify Serial Number > OnNext now has:

-- These actions are performed when the Next button is clicked.

-- get the serial number that the user entered
local strSerial = SessionVar.Expand("%SerialNumber%");

-- the name of the serial number list you want to use, e.g. "Serial List 1"
-- (use nil to search through all of the serial number lists)
local strListName = nil;

-- from _SUF70_Global_Functions.lua:
-- search through the specified serial number list for a match
local bSerialIsValid = g_IsSerialNumberInList(strSerial, strListName);

-- check license online

checkvars = { pid=19, email=SessionVar.Get("%Emailaddress%") };
valid = HTTP.SubmitSecure("https://domain.com/test.php", checkvars, SUBMITWEB_GET, 20, 443, nil, nil);
if (String.Compare(valid, "Mincount") == 1) then
Dialog.Message("No valid license", "No valid license found. The application will exit now. Please contact Support!", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
Application.Exit();
end
if (String.Compare(valid, "Mincount") == 1) then
Dialog.Message("Annual license expired", "Your license needs renewal. The application will exit now. Please go to http://domain.com/renew.php/ to renew your license!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit();
end

if (String.Compare(valid, "Maxcount") == 0) then
valid = true;
end

-- if the user entered a valid serial number, proceed to the next screen,
-- otherwise display an error message and check whether they have any retries left
if (bSerialIsValid) and (valid) then

-- advance to the next screen
Screen.Next();

else

-- user entered an invalid serial number

SerialNumberScreen.AttemptCount = SerialNumberScreen.AttemptCount + 1;

-- display an 'Invalid serial number' message
Dialog.Message(SetupData.GetLocalizedString("MSG_ERROR"), SetupData.GetLocalizedString("ERR_INVALID_SERIAL"));

-- if the user is out of retries, exit the application
if(SerialNumberScreen.AttemptCount >= SerialNumberScreen.MaxAttempts) then
Application.Exit(0);
end

end

villario
09-02-2009, 07:40 AM
Since I cannot Edit my replies:

I have now:

PHP online: print "string";

then in Verify Serial Number > OnNext

-- These actions are performed when the Next button is clicked.

-- get the serial number that the user entered
local strSerial = SessionVar.Expand("%SerialNumber%");

-- the name of the serial number list you want to use, e.g. "Serial List 1"
-- (use nil to search through all of the serial number lists)
local strListName = nil;

-- from _SUF70_Global_Functions.lua:
-- search through the specified serial number list for a match
local bSerialIsValid = g_IsSerialNumberInList(strSerial, strListName);

-- check license online

checkvars = { pid=19, email=SessionVar.Get("%Emailaddress%") };
valid = HTTP.SubmitSecure("https://domain.com/test.php", checkvars, SUBMITWEB_POST, 20, 443, nil, nil);

if (String.Compare(valid, "Mincount") == 0) then
Dialog.Message("No valid license", "No valid license found. The application will exit now. Please contact Support!", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
Application.Exit();
end
if (String.Compare(valid, "MinAcount") == 0) then
Dialog.Message("Annual license expired", "Your license needs renewal. The application will exit now. Please go to http://domain.com/update/ to renew your license!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit();
end

if (String.Compare(valid, "Maxcount") == 0) then
local svalid = true;
end

-- if the user entered a valid serial number, proceed to the next screen,
-- otherwise display an error message and check whether they have any retries left
if (bSerialIsValid and svalid) then

Screen.Next();

else

-- user entered an invalid serial number

SerialNumberScreen.AttemptCount = SerialNumberScreen.AttemptCount + 1;

-- display an 'Invalid serial number' message
Dialog.Message(SetupData.GetLocalizedString("MSG_ERROR"), SetupData.GetLocalizedString("ERR_INVALID_SERIAL"));

-- if the user is out of retries, exit the application
if(SerialNumberScreen.AttemptCount >= SerialNumberScreen.MaxAttempts) then
Application.Exit(0);
end

end

Alas, still not working!
Any suggestions what can still be wrong?
thanks,
Villario