Using php scripts from BMX
BlitzMax Forums/BlitzMax Tutorials/Using php scripts from BMX| 
 | ||
| Ok folks, I used ReadStream() for another cool test! This time we're going to execute a php script that will deliver the MD5 hash from any string given to the php script. Ok, let's start! 'First, we gonna set up the strictmode
Strict
Function inetscript:String(myurl:String)
	'Now we gonna open the requested URL to read
	Local myip:TStream		= ReadStream(myurl$)
	
	'We need a var to store the string that will be given
	'back by the php script
	Local ipstring:String	= ""
	
	'Successfully opened the requested URL?
	If Not myip
		
		'If not then we let the user know
		ipstring$ = "Error!"
	Else
		'If yes then we read all that our script
		'has for us
		While Not Eof(myip)
		
			'And store the output line by line
			ipstring$ :+ ReadLine(myip)
		Wend
		
		'Don't forget to close the opened stream in the end!
		CloseStream myip
		
	EndIf
	
	'Just return what we've got	
	Return ipstring$
	
End Function
Print inetscript$("http::www.infernalsoftware.com/md5.php?test=blablablubb")Try it, it will work (I didn't delete the md5.php from my site so feel free to try it out ;-))! | 
| 
 | ||
| Neat!  Thanks for sharing that... | 
| 
 | ||
| Hehe, that's just kind of by-product from my current project ^^ Thanks to the MD5 BlitzMax function from Tom Darby I don't need to use PureBasic anymore (all I need now is a GUI module, if Mark don't releases the official module soon, I'll probably go with filax IGlass)... | 
| 
 | ||
| You need to move the CloseStream line into the Else part of the If block above it. | 
| 
 | ||
| Changed it, thanks ^^ | 
| 
 | ||
| Very nice.This is some easy code to compare application versions. Connect to php script and get latest version. if latest > present then inform user new version available. | 
| 
 | ||
| Put this tip on the wiki. I'll need it later :) | 
| 
 | ||
| With this code you can also interface some MySQL database (though it is a bit complicated because you have to walk some extra mile) :-D | 
| 
 | ||
| Can you post the test-php script with comments? | 
| 
 | ||
| I've put comments in the code for those of you who need it ^^ | 
| 
 | ||
| I want the php script so I can setup my own to use in my game. But I don't know anything about php. I'm probably just a google-search away from getting some free php scripts and tutorials, but it would be nice if you showed your php script - with comments. | 
| 
 | ||
| I put this technique into my code this morning and it works great!  Thanks again! I was worrying about not having OpenTCPConnection anymore and was wondering what the hell I was going to do on the Mac as well. Didn't even occur to me that streams would "just work". Awesome. :) | 
| 
 | ||
| @Wave - Using this technique just to get an MD5 hash is pretty pointless, it's only to demonstrate the use of the 'http::' stream protocol. It'd only be something like... <?php echo md5($test); ?>...any way (it has been a couple of years since I've touched PHP though). BMax code to generate an MD5 hash can be found here. | 
| 
 | ||
| Isn't it a good way to ensure that people are using the latest and unmodified game-files? Especially for online games? What would be the best way to have a web-based highscore? One that perhaps could be put in a php script. | 
| 
 | ||
| TwoEyedPete is right about that script ^^  What would be the best way to have a web-based highscore? One that perhaps could be put in a php script. Well, you can do pretty much with MD5 to ensure a secure session. And for that highscore stuff: I think that I've seen some php script just today on this board (can't remember where exactly)... /Edit: Found it here: http://www.blitzbasic.com/Community/posts.php?topic=50177 | 
| 
 | ||
| Thanks, this is really useful =) |