Skip to content
⌘ NSIS Forum Archive

Serial Strangeness

25 posts

angusi#

Serial Strangeness

Hi there 🙂

I have this code which i use to validate a serial code: the user types their serial code in a box which then posts to a webpage to check against a MySQL database and says VALID if the key is valid and INVALID if not

if the key is entered correctly, there is no problem. If the key is NOT then the page for entering the serial is shown again. The only difference is that when you enter the key the second time, it doesn't matter if the key is correct or not, it doesn't bother to validate. Please advise. I have posted the bit of code which validates below:


Function SerialPageShow
!insertmacro MUI_HEADER_TEXT "Enter Serial Code" "Enter the software serial code to continue."

PassDialog:😁ialog Serial \
/HEADINGTEXT 'Please enter the serial code...' \
/CENTER \
/BOXDASH 12 70 5 '' \
/BOXDASH 92 70 5 '' \
/BOXDASH 172 70 5 '' \
/BOXDASH 252 70 5 '' \
/BOX 332 70 5 ''

Pop $R0 # success, back, cancel or error
FunctionEnd

Function SerialPageLeave

## Pop values from stack
Pop $R1
Pop $R2
Pop $R3
Pop $R4
Pop $R5

;!insertmacro MUI_HEADER_TEXT "Validating..." "Please Wait"
;!insertmacro MUI_INSTALLOPTIONS_DISPLAY "validateSerial.ini"

;MessageBox MB_OK "Break1"

FunctionEnd

Function validateSerial

;MessageBox MB_OK "Break2"

;## Disable the Back button
;GetDlgItem $R6 $HWNDPARENT 3
;EnableWindow $R6 0
;## Disable the Next button
;GetDlgItem $R6 $HWNDPARENT 1
;EnableWindow $R6 0

GetTempFileName $0
InetLoad::load /post "licence=$R1-$R2-$R3-$R4-$R5" "http://www.mysite.co.uk/install/verify.php" "$0" /slient ""
Pop $1 # $1 now holds the exit code for above

FileOpen $2 $0 "r"
FileRead $2 $3
FileClose $2

${If} $3 == 'INVALID'
MessageBox MB_OK|MB_ICONEXCLAMATION "Invalid Serial"
Call SerialPageShow
${Else}
Goto serialOK
${EndIf}

Abort

serialOK:
FunctionEnd
Afrow UK#
Move the contents of validateSerial into SerialPageLeave.
You don't Call SerialPageShow to show the page again... you just call Abort.

Stu
angusi#
you mean like this:

Function SerialPageLeave

## Pop values from stack
Pop $R1
Pop $R2
Pop $R3
Pop $R4
Pop $R5

;!insertmacro MUI_HEADER_TEXT "Validating..." "Please Wait"
;!insertmacro MUI_INSTALLOPTIONS_DISPLAY "validateSerial.ini"

;MessageBox MB_OK "Break1"


;MessageBox MB_OK "Break2"

;## Disable the Back button
;GetDlgItem $R6 $HWNDPARENT 3
;EnableWindow $R6 0
;## Disable the Next button
;GetDlgItem $R6 $HWNDPARENT 1
;EnableWindow $R6 0

GetTempFileName $0
InetLoad::load /post "licence=$R1-$R2-$R3-$R4-$R5" "http://www.mysite.co.uk/site/verify.php" "$0" /slient ""
Pop $1 # $1 now holds the exit code for above

FileOpen $2 $0 "r"
FileRead $2 $3
FileClose $2

${If} $3 == 'INVALID'
MessageBox MB_OK|MB_ICONEXCLAMATION "Invalid Serial"
Call SerialPageShow
${Else}
Goto serialOK
${EndIf}

Abort

serialOK:

FunctionEnd
or like this:

Function SerialPageLeave
;MessageBox MB_OK "Break1"


;MessageBox MB_OK "Break2"

;## Disable the Back button
;GetDlgItem $R6 $HWNDPARENT 3
;EnableWindow $R6 0
;## Disable the Next button
;GetDlgItem $R6 $HWNDPARENT 1
;EnableWindow $R6 0

GetTempFileName $0
InetLoad::load /post "licence=$R1-$R2-$R3-$R4-$R5" "http://www.mysite.co.uk/site/verify.php" "$0" /slient ""
Pop $1 # $1 now holds the exit code for above

FileOpen $2 $0 "r"
FileRead $2 $3
FileClose $2

${If} $3 == 'INVALID'
MessageBox MB_OK|MB_ICONEXCLAMATION "Invalid Serial"
Call SerialPageShow
${Else}
Goto serialOK
${EndIf}

Abort

serialOK:

FunctionEnd
Using the first method, the installer exits the second time a code is entered whether valid or not.
Afrow UK#
Function SerialPageLeave

## Pop values from stack
Pop $R1
Pop $R2
Pop $R3
Pop $R4
Pop $R5

GetTempFileName $0
InetLoad::load /post "licence=$R1-$R2-$R3-$R4-$R5" /silent "" "http://www.mysite.co.uk/site/verify.php" "$0" /end
Pop $1 # $1 now holds the exit code for above

FileOpen $2 $0 "r"
FileRead $2 $3
FileClose $2

${If} $3 == 'INVALID'
MessageBox MB_OK|MB_ICONEXCLAMATION "Invalid Serial"
Abort
${EndIf}

FunctionEnd
Notice I have changed your InetLoad parameters a bit so that it's to the readme spec.

Stu
angusi#
Edit (again!): The installer now simply says the code is invalid, even if the database doesn't say INVALID, but says Serial Validated
angusi#
so should I switch them round?
still says invalid for all serials

don't know if this is just my pc, but the installer takes at least 20 seconds to try and check (and fail) the serial the first time then only about 2 seconds the second, third, fourth etc times.
Afrow UK#
Check the exit code. Your code would not have worked because all switches go before the url parts, not to mention you had /slient not /silent 🙂

Stu
angusi#
ahh 🙂

like this: MessageBox MB_OK|MB_ICONEXCLAMATION "$1"

the message box says "SendRequest Error"

and the installer has now started validating every code... 😕

if you want to take a look at the installer to see for yourself i can post it here.
Afrow UK#
If there is an error then obviously there is something wrong. Try removing the /silent "" bit.

Stu
angusi#
the installer just goes straight onto the components page and doesn't try to access the validate.php file
Afrow UK#
There must be something wrong with your php script or website. The code works fine for me using a different php script with post data.

Stu
Takhir#
Please note, that FileRead returns string with newline char at the end (if any), so comparision may require a kind of trim for incoming string (or just use 'INVALIDE$\n' in ${if} statement). The following test works correct for me:
    InetLoad::load /post "licence=INVALID" /silent "" "http://localhost/echo.php" "$EXEDIR\echo.htm" /end
Pop $0 # "OK" means okay
FileOpen $2 "$EXEDIR\echo.htm" "r"
FileRead $2 $3
FileClose $2
MessageBox MB_OK "Download Status: $0, Result = <$3>"
StrCmp $3 "INVALID" 0 +2
MessageBox MB_OK "Invalid Serial"
for the following test php
<?php $n = 0; foreach($_REQUEST as $v) {echo $v; if($n > 0) echo "\n"; $n++; } ?>
But comparision require 'INVALIDE$\n' if newline presents in the server reply.
angusi#
Originally posted by Afrow UK
There must be something wrong with your php script or website. The code works fine for me using a different php script with post data.

Stu
what is your php script like?
i've checked the php manually (launched my browser and gone to the URL) and when i "post" an invalid code the source of the page simply says
INVALID
and when i "post" a valid one,
Serial Validated
Thats all the source shows.
Afrow UK#
My PHP script is just a normal webpage. The only thing I can think of is make sure you set the content type to plain text before displaying your result in the PHP script:

header("Content-Type: text/plain");

Stu
angusi#
:l still doesn't work...

a temporary URL for the script is Here - At the moment any code should read INVALID...
angusi#
This is really starting to annoy me now lol... I tried putting some of this into my script:

Originally posted by Takhir

InetLoad::load /post "licence=$R1-$R2-$R3-$R4-$R5" /silent "" "http://www.mysite.com/site/verify.php" "$EXEDIR\echo.htm" /end
Pop $0 # "OK" means okay
FileOpen $2 "$EXEDIR\echo.htm" "r"
FileRead $2 $3
FileClose $2
MessageBox MB_OK "Download Status: $0, Result = <$3>"
StrCmp $3 "INVALID" 0 +2
MessageBox MB_OK "Invalid Serial"
the $EXEDIR\echo.htm reads INVALID, but not in text/plain formatting - is that somehow relevant?
Afrow UK#
Make sure you aren't placing any new line characters on the end of the output string. FileRead reads new line characters as well.

Stu
Afrow UK#
Sorry?
Just make sure in your PHP script you're echoing "INVALID" and not "INVALID\r\n" for example.

What does your message box display?
MessageBox MB_OK "Download Status: $0, Result = <$3>"

Stu