Game Development Community

Problems with HTTP Objects

by Bob Mann · in Torque 3D Professional · 10/07/2011 (7:25 am) · 4 replies

I am trying to work with some HTTP objects to make a login.

It always hands back the false variable in Torque. But it works fine from a browser.


pitfallstudios.com:80/scripts/auth.php?username=test-lol

PHP
$con = mysql_connect("localhost","----","---------");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}


mysql_select_db("pfs", $con);
//echo $_GET['username'];
$username = $_GET['username'];    
$exploded_username = explode('-',$username);    
$newusername = $exploded_username[0];    
$password = $exploded_username[1];  

      

$result = mysql_query("SELECT * FROM users WHERE username='$newusername' and password='$password'");  

if(mysql_num_rows($result) == 0) 
{  
	echo "false";  
} 
else 
{  
	echo "true";    
}
Torque

function login()  
{  

	%username = $urname;  
	%password = $pass;   
			   
	%server = "pitfallstudios.com:80";  
	%path = "/scripts/";  
	%script = "auth.php?";  
	
	%query = "username="@%username@"-"@%password;  
	
	
	%hto = new HTTPObject(Login); 
	%hto.get(%server,%path @ %script,%query);  
	
	echo(%server @ %path @ %script @ %query);

}

function Login::onLine(%this,%line)  
{  
	echo("Server Returned : " @ %line );
}
Log
pitfallstudios.com:80/scripts/auth.php?username=test-lol
Server Returned : HTTP/1.1 200 OK
Server Returned : Connection: close
Server Returned : Date: Fri, 07 Oct 2011 14:23:23 GMT
Server Returned : Server: Microsoft-IIS/6.0
Server Returned : X-Powered-By: ASP.NET
Server Returned : X-Powered-By: PHP/5.2.6
Server Returned : Content-type: text/html
Server Returned : 
Server Returned :     false

#1
10/07/2011 (9:43 am)
%script = "auth.php";    
%query = "username="@%username@"-"@%password;

This works for me. Not sure if it's the right way of doing this stuff.
#2
10/07/2011 (12:12 pm)
Is this copied from your script?

%script = "auth.php?";

I doubt the name of that file ends in a question mark....

Note the code Lunacy posted:

%script = "auth.php";

which he says works for him.

Typos are the bane of my existence....

Just a note - I believe the ? is a wildcard, but it requires something to be at that position. So that would accept auth.phpa or auth.php2, but not auth.php. An * should work there because it doesn't require anything in its place. I haven't read it in a while, so I might be whistling out my wazoo....
#3
10/07/2011 (12:50 pm)
The "?" is not a wildcard actually, it's more like a delimiter used to say "here comes the parameters", and I guess the engine implicitly adds it to the URL (between %script and %query). Note that
%script = "auth.php?username=" @ %username @ "-" @ %password
should also work.
#4
10/07/2011 (2:49 pm)
Thank you. Did not notice that.