Read a text file?

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!

Moderator: General Moderators

derchris
Forum Commoner
Posts: 44
Joined: Sat Jun 10, 2006 6:14 pm

Post by derchris »

I think it should be elseif instead of if for the blacklist.

Say, I type in this blacklisted serial, it first checks if it valid, it is not and goes to the next else.
But it will never reach the next if.
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Post by m0u53m4t »

derchris
Forum Commoner
Posts: 44
Joined: Sat Jun 10, 2006 6:14 pm

Post by derchris »

But not correct.
According to your script, one should be redirected to Altavista if the Serial is wrong,
but I got redirected to Google
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Post by m0u53m4t »

Wierd... Can you test my vb application for me to see if it works ok. http://cardiffhigh.cardiff.sch.uk/~jami ... /Login.exe I recommend you scan it for viruses first just in case. Use this key: 7JKD-F982-J894-NH7I-8KDF this password: "Yoda" and this password "anewhope".
derchris
Forum Commoner
Posts: 44
Joined: Sat Jun 10, 2006 6:14 pm

Post by derchris »

I don't have the .NET Framework installed on my machine
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Post by m0u53m4t »

Ah... how do people get that?
derchris
Forum Commoner
Posts: 44
Joined: Sat Jun 10, 2006 6:14 pm

Post by derchris »

You can download it from the MS website
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Post by m0u53m4t »

Ah. That will be part of a program I plan on selling... I think I'll mention they need that... :lol:
SKDevelopment
Forum Newbie
Posts: 13
Joined: Thu Jan 26, 2006 10:42 am

Post by SKDevelopment »

m0u53m4t wrote: and if the serial is right, it goes to google, if its black listed it goes to Yahoo.
No. In your case it always goes to Google. It is because '43T7-9H2O-348Y-UVH2-80VN' and '79EU-IDJH-J09F-UAWE-HRF9' are not empty strings and always evaluated to TRUE.

I think what you meant is:

Code: Select all

$serial = $_GET["serial"]; 
if (($serial == '7JKD-F982-J894-NH7I-8KDF' || $serial == '43T7-9H2O-348Y-UVH2-80VN' || $serial == '79EU-IDJH-J09F-UAWE-HRF9')) { // Valid serial keys 
header( 'Location: http://www.google.com' ) ; 
} 
else { 
header( 'Location: http://www.altavista.com' ) ; 
}

// Attention !!! This condition is never checked !!!
if (($serial == '7K7D-SGF7-J894-NH7I-J8G5')) { // Blacklisted serials 
header( 'Location: http://www.yahoo.com' ) ; 
}
Even in this case your 2nd condition is never checked. Because by the 1st condition you will be redirected either to Google or to Altavista. You will be never redirected to Yahoo.

Edit: I see the last has been mentioned already.
--
Best Regards,
Sergey Korolev
www.SKDevelopment.com
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Post by m0u53m4t »

Then why does it work? http://juniorfiles.t35.com/reg.php?seri ... -NH7I-J8G5 should take you to yahoo.
SKDevelopment
Forum Newbie
Posts: 13
Joined: Thu Jan 26, 2006 10:42 am

Post by SKDevelopment »

I think I should add this to my previous post. I said the 2nd condition will never be checked. Formally speaking it will be checked. The PHP Parser will parse the script to the end no matter which headers have been sent to the browser already. But anyway because of the 1st condition the browser will be redirected either to Google or to Altavista. And though the 2nd "if" will be parsed by the PHP parser anyway, the redirect to Yahoo will have no effect. Just as if the 2nd "if" was not parsed at all.
SKDevelopment
Forum Newbie
Posts: 13
Joined: Thu Jan 26, 2006 10:42 am

Post by SKDevelopment »

m0u53m4t wrote:Then why does it work? http://juniorfiles.t35.com/reg.php?seri ... -NH7I-J8G5 should take you to yahoo.
Very interesting. Never checked it like that. This means the 2nd "Location" header takes precedence if 2 "Location" headers are sent.

But I think it would be better for you to corrected your script. Such behavior does not look very reliable to me.

I tried to look at it with FireFox with LiveHTTPHeaders. Only 1 "Location" header is shown in each case. I did not explore the situation any further.

Edit: Gave a wrong example. Removed it. Sorry.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

m0u53m4t wrote:Then why does it work? http://juniorfiles.t35.com/reg.php?seri ... -NH7I-J8G5 should take you to yahoo.
Just because you send a header redirect does not mean the script will terminate at taht point. You'll notice nearly everytime anyone uses header redirect it is proceeded by an exit() call so no other code is called.
SKDevelopment
Forum Newbie
Posts: 13
Joined: Thu Jan 26, 2006 10:42 am

Post by SKDevelopment »

I think your script could look something like this:

Code: Select all

<?php
$serial = $_GET["serial"]; 
if (in_array($serial,array('7JKD-F982-J894-NH7I-8KDF','43T7-9H2O-348Y-UVH2-80VN','79EU-IDJH-J09F-UAWE-HRF9'))) { // Valid serial keys 
 header( 'Location: http://www.google.com' ) ; 
} elseif($serial == '7K7D-SGF7-J894-NH7I-J8G5') { // Blacklisted serials 
 header( 'Location: http://www.yahoo.com' ) ;    
} else { 
 header( 'Location: http://www.altavista.com' ) ; 
} 
?>
User avatar
m0u53m4t
Forum Contributor
Posts: 101
Joined: Wed Apr 19, 2006 7:47 am
Location: Wales

Post by m0u53m4t »

Jcart wrote:
m0u53m4t wrote:Then why does it work? http://juniorfiles.t35.com/reg.php?seri ... -NH7I-J8G5 should take you to yahoo.
Just because you send a header redirect does not mean the script will terminate at taht point. You'll notice nearly everytime anyone uses header redirect it is proceeded by an exit() call so no other code is called.
But if, like here, I do want the rest done then isn't that ok not to call exit()?
Post Reply