PhP Login Help

Blitz3D Forums/Blitz3D Programming/PhP Login Help

alloidgames(Posted 2006) [#1]
Hi I've got this function...

Function LogIn()

name$ = Input("Enter name : ")
pass$ = Input("Enter password : ")

name = Replace(name," ","_")
pass = Replace(pass," ","_")
name = name + "|"

tcp = OpenTCPStream("alloidgames.com", 80)

If tcp Then
	WriteLine tcp, "GET /PHPFILE?type=2&name=" + name$ + "&pass="+ pass + " HTTP/1.0"
	WriteLine tcp, "HOST: alloidgames.com"
	WriteLine tcp, ""
EndIf

CloseTCPStream tcp 

tcp = OpenTCPStream("www.alloidgames.com",80)
If tcp Then
	WriteLine tcp,"GET http://www.alloidgames.com/TEMPORARY HASH FILE"
	WriteLine tcp,Chr$(10)
	If Not Eof(tcp) Then
		Repeat
			lastline$ = ReadLine$(tcp)
		Until Eof(tcp)
	End If
End If
CloseTCPStream tcp

tcp = OpenTCPStream("www.alloidgames.com",80)
If tcp Then
	WriteLine tcp,"GET http://www.alloidgames.com/DATABASE FILE"
	WriteLine tcp,Chr$(10)
	If Not Eof(tcp) Then
		Repeat
			curline$ = ReadLine$(tcp)
			If curline$ = lastline$ Then
				Print "Success"
				WaitKey
				Exit
			End If
		Until Eof(tcp)
	End If
End If
CloseTCPStream tcp

WaitKey

End Function


And here's my php script...

[code]
<html>
<body>

<?php
$reqType = $_REQUEST['type'];
$newString = $_REQUEST['name'];
$newPass = $_REQUEST['pass'];
$newPass = md5($newPass);
if($reqType == "2")
$fp = fopen( "TEMPORARY HASH FILE" , "a+" ); //Holds the temporary hashed info to check against database
elseif($reqType == "1") //Open data file to add new act info
$fp = fopen( "DATABASE FILE.txt" , "a+" );
fwrite( $fp, $newString . $newPass);
fwrite( $fp, "\n");
fclose($fp)
?>

</body>
</html>
[code]

The way it works, is the user first makes an account, and their name and password get sent to the php file, which hashes it and sends it to the database file. Then the user can login, and when they do that they enter their name and password. These then get sent to the php file with reqType of 2, meaning that they get hashed and sent to the temporary data file. Then Blitz opens the temp one, and ideally reads the most recent entry (this is where I start having problems). Then it opens the permanent database file, and cycles through each entry to see if it matches the temporary one. The problem seems to come with reading the temporary info, because it almost never comes up equal! Any help would be, as always, greatly appreciated.


jfk EO-11110(Posted 2006) [#2]
maybe the problem's somewhere here:
	If Not Eof(tcp) Then
		Repeat
			lastline$ = ReadLine$(tcp)
		Until Eof(tcp)
	End If

servers seem to add a line after every line, containing the string length, if I recall correctly. Maybe you should try something like this înstead:
	If Not Eof(tcp) Then
		lastline$ = ReadLine$(tcp)
		Repeat
			dummy$ = ReadLine$(tcp)
		Until Eof(tcp)
	End If



alloidgames(Posted 2006) [#3]
But then it only reads the first line of the stream every time it is opened? Doesn't it need to repeat to get the most recent info every time?

Sorry for the delay-for-reply/inability to test it for myself, I just got a new computer and have been busy transfering everything and setting it up and stuff.