Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Serial Strangeness (http://forums.winamp.com/showthread.php?t=281896)

angusi 21st November 2007 20:05

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:

code:

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

PassDialog::Dialog 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 21st November 2007 20:58

Move the contents of validateSerial into SerialPageLeave.
You don't Call SerialPageShow to show the page again... you just call Abort.

Stu

angusi 22nd November 2007 18:05

you mean like this:
code:

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:
code:

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 22nd November 2007 19:50

code:
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 23rd November 2007 14:37

Edit (again!): The installer now simply says the code is invalid, even if the database doesn't say INVALID, but says Serial Validated

Afrow UK 23rd November 2007 18:03

I have swapped the /silent and /post switched around.

Stu

angusi 24th November 2007 11:56

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 24th November 2007 13:09

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 24th November 2007 13:29

ok... i'm now a little confused... can you post the code to show what you mean... thanks.

Afrow UK 24th November 2007 19:57

Pop $1 # $1 now holds the exit code for above

Check the value of $1.

Stu

angusi 24th November 2007 20:01

umm... how would i do that?

Afrow UK 24th November 2007 20:42

With a MessageBox perhaps :)

Stu

angusi 25th November 2007 10:02

ahh :)

like this: MessageBox MB_OK|MB_ICONEXCLAMATION "$1"

the message box says "SendRequest Error"

and the installer has now started validating every code... :confused:

if you want to take a look at the installer to see for yourself i can post it here.

Afrow UK 25th November 2007 14:17

If there is an error then obviously there is something wrong. Try removing the /silent "" bit.

Stu

angusi 25th November 2007 15:28

the installer just goes straight onto the components page and doesn't try to access the validate.php file

Afrow UK 25th November 2007 16:23

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 25th November 2007 16:36

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:
code:
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 Code:

<?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 26th November 2007 18:11

Quote:

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
code:
INVALID

and when i "post" a valid one,
code:
Serial Validated

Thats all the source shows.

Afrow UK 26th November 2007 18:46

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 29th November 2007 14:06

:l still doesn't work...

a temporary URL for the script is Here - At the moment any code should read INVALID...

angusi 1st December 2007 14:49

This is really starting to annoy me now lol... I tried putting some of this into my script:

Quote:

Originally posted by Takhir
code:

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 2nd December 2007 13:35

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

angusi 2nd December 2007 14:20

would that not mean that if would validate every code?

Afrow UK 2nd December 2007 15:15

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

angusi 4th December 2007 17:45

"INVALID"


All times are GMT. The time now is 05:59.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.