Page 1 of 2
Read a text file?
Posted: Sat Jun 10, 2006 8:51 am
by m0u53m4t
Im making a very simple register program for VB where there is a webbrowser where you enter you're serial number. The program then reads when you've got to the success page (in this case
http://www.google.com) then the program accepts you. I want to make it read a file (for example:
http://me.myhost.com/key.txt and compare $serial to the contents. How could I do that?
This is my code so far:
Code: Select all
<?php
$serial = $_GET["serial"];
if (($serial == '1234-5678-91011')) {
header( 'Location: http://www.google.com' ) ;
}
else {
echo 'Incorrect serial number';
}
?>
Posted: Sat Jun 10, 2006 9:36 am
by dibyendrah
Please try this.
Code: Select all
<?php
$serial = $_GET["serial"];
// get contents of a file into a string
$filename = "http://me.myhost.com/key.txt";
$handle = fopen( $filename, "rb");
while( !feof( $handle )){
$line = fgets( $handle ); //read line by line
if($serial==$line){
return(true); //if serial matches with line, return true
fclose($handle); //close the file
}
}
return(false);
?>
Regards,
Dibyendra
Posted: Sat Jun 10, 2006 11:08 am
by m0u53m4t
I'm getting this error:
Code: Select all
Warning: fopen(): URL file-access is disabled in the server configuration in /home/freehost/t35.com/j/u/juniorfiles/reg.php on line 6
Warning: fopen(http://cardiffhigh.cardiff.sch.uk/~jamie.sargant/key.txt): failed to open stream: no suitable wrapper could be found in /home/freehost/t35.com/j/u/juniorfiles/reg.php on line 6
Warning: feof(): supplied argument is not a valid stream resource in /home/freehost/t35.com/j/u/juniorfiles/reg.php on line 7
Warning: fgets(): supplied argument is not a valid stream resource in /home/freehost/t35.com/j/u/juniorfiles/reg.php on line 8
Then the last two just loop and keep giving them again.
Posted: Sat Jun 10, 2006 11:55 am
by Li0rE
t35 doesnt let you use fopen i guess, but try setting permissions of the .txt file to 777
Posted: Sat Jun 10, 2006 12:22 pm
by m0u53m4t
Its hosted through dav. How do I CHmod it from there?
Posted: Sat Jun 10, 2006 1:56 pm
by feyd
By having a script that directly reads the serial numbers list you'll compromize all the valid ones..
Posted: Sat Jun 10, 2006 2:10 pm
by m0u53m4t
The file will only have one bit of text in (the entire contents may be "1234-5678-9101"). I just need the php to compare the user entered string entirely to the contents of that file.
Posted: Sat Jun 10, 2006 5:05 pm
by Li0rE
if the text file will have only 1 bit of text, why not just put the serial in the script?
Posted: Sat Jun 10, 2006 7:05 pm
by m0u53m4t
...good point...

... how would I do it if it was more than one?
Posted: Sat Jun 10, 2006 7:38 pm
by derchris
You could put them all in an array and then check the input against it.
Posted: Sun Jun 11, 2006 5:43 am
by m0u53m4t
How can I put them in an array?
Posted: Sun Jun 11, 2006 6:13 am
by derchris
Code: Select all
$serial = array(serials => '12345', '67890', '09876');
Posted: Sun Jun 11, 2006 8:12 am
by m0u53m4t
Is there any advantage of doing that over doing this:
Code: Select all
if (($serial == '12345' or '67890' or '09876')) {
Posted: Sun Jun 11, 2006 8:27 am
by derchris
I don't know if there is any advantage or disadvantage in doing it this way,
but I will look better.
And you can have access to all the serials later in the Script if you need them.
Posted: Sun Jun 11, 2006 8:37 am
by m0u53m4t
This is my entire script:
Code: Select all
<?php
$serial = $_GET["serial"];
if (($serial == '7JKD-F982-J894-NH7I-8KDF' or '43T7-9H2O-348Y-UVH2-80VN' or '79EU-IDJH-J09F-UAWE-HRF9')) { // Valid serial keys
header( 'Location: http://www.google.com' ) ;
}
else {
header( 'Location: http://www.altavista.com' ) ;
}
if (($serial == '7K7D-SGF7-J894-NH7I-J8G5')) { // Blacklisted serials
header( 'Location: http://www.yahoo.com' ) ;
}
?>
and if the serial is right, it goes to google, if its black listed it goes to Yahoo.