HTTP script
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
12-22-2006 13:24
I need a script that will access a website like http://www.mywebsite.com/user.php?name=With the players name at the end and grab the number value that is on the webpage and adds it to a variable in game. I hope I am explaining right.. It seems pretty simple but I can't figure it out.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-22-2006 13:38
From: Danx Daniels I need a script that will access a website like http://www.mywebsite.com/user.php?name=With the players name at the end and grab the number value that is on the webpage and adds it to a variable in game. I hope I am explaining right.. It seems pretty simple but I can't figure it out. check the HTTP Wikki
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
script
12-22-2006 13:40
I have, and I'm still confused, thought maybe someone here could help simplify it for me.
|
|
Woopsy Dazy
Registered User
Join date: 12 Nov 2006
Posts: 173
|
12-22-2006 14:04
Here's a very simple sample default { state_entry() { } touch_start(integer something) { username = llEscapeURL(llDetectedName(0)); url = "http://yoursite.com/webpage.php?UserName=" + username; requestid = llHTTPRequest(urlstring,[HTTP_METHOD,"GET"],""); } http_response(key request_id, integer status, list metadata, string body) { if (request_id == requestid) { llOwnerSay("The web page response was: " + body); } } }
Haven't tested it, should work. Excuse the strange formatting. Not sure how you make tabs in here. One very important thing is that the response you get from web-page is the html-body. What you see if you click view source in browser. There's a limit of 2048 characters so you must not respond with a lot of html-tags and styles and crap. So basically your php-page should look like this: <?php UserName = $_GET["UserName"]; # Do a lot of stuff here but dont write anything # Now write your response to SL echo "16453"; #UserID ?> echo "Response";
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Yes
12-22-2006 14:22
That looks like it should work, but gives me an error, name not defined within scope when I try to save it.
|
|
Woopsy Dazy
Registered User
Join date: 12 Nov 2006
Posts: 173
|
12-22-2006 15:19
From: Danx Daniels That looks like it should work, but gives me an error, name not defined within scope when I try to save it. Ah yes, I forgot to declare the variables. So add string before username and url like this: string url = http://your...;
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
hmm
12-22-2006 15:31
So it should look like : default { state_entry() { } touch_start(integer something) { string username = llEscapeURL(llDetectedName(0)); string url = "http://mywebsite.com/user.php?username=" + username; requestid = llHTTPRequest(urlstring,[HTTP_METHOD,"GET"],""  ; } http_response(key request_id, integer status, list metadata, string body) { if (request_id == requestid) { llOwnerSay("The web page response was: " + body); } } } That still gives me an error
|
|
Dustin Widget
Script Monkey for hire
Join date: 15 Feb 2006
Posts: 101
|
12-22-2006 15:39
the requetid needs to be declared as a key, so: key requestid; default { state_entry() { } touch_start(integer something) { string username = llEscapeURL(llDetectedName(0)); string url = "http://mywebsite.com/user.php?username=" + username; requestid = llHTTPRequest(urlstring,[HTTP_METHOD,"GET"],""  ; } http_response(key request_id, integer status, list metadata, string body) { if (request_id == requestid) { llOwnerSay("The web page response was: " + body); } } }
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Thanks
12-22-2006 15:47
I figured that part out, also the 'urlstring' needed to be changed to just 'url' and it works just like I wanted.
Next question, the body response from the webpage is a single number, can I take that number and turn it into a variable, or can I use body as a variable?
The number is going to represent an amount of money to be given, so I will need to be able to use it in a line to give money.
|
|
Woopsy Dazy
Registered User
Join date: 12 Nov 2006
Posts: 173
|
12-22-2006 15:58
From: Danx Daniels I figured that part out, also the 'urlstring' needed to be changed to just 'url' and it works just like I wanted. Next question, the body response from the webpage is a single number, can I take that number and turn it into a variable, or can I use body as a variable? The number is going to represent an amount of money to be given, so I will need to be able to use it in a line to give money. Yes, if the result is pure integer (like 1350) you just write: integer money = (integer)body; or use float for decimals. Always easier to write code in PHP/ASP so try to format numbers in the web-page rather than in LSL-scripting.
|
|
Thaddeus Ning
Registered User
Join date: 8 Dec 2006
Posts: 1
|
Another question......
12-23-2006 19:01
From: Woopsy Dazy Here's a very simple sample ... One very important thing is that the response you get from web-page is the html-body. What you see if you click view source in browser. There's a limit of 2048 characters so you must not respond with a lot of html-tags and styles and crap. So basically your php-page should look like this: <?php UserName = $_GET["UserName"]; # Do a lot of stuff here but dont write anything # Now write your response to SL echo "16453"; #UserID ?> echo "Response"; I'm very interested in trying this out. I've never done ANY web stuff, so much of this is a absolute mystery to me - I've always done the "backend" database and comm protocol work, but nothing on the front end. I do have a Wordpress blog set up, on my own hosted domain, so I have access to MySQL, PHP, and the like. Assuming that I have somewhere to put the page on my domain - which I do - are you saying that I could just put exactly the php code shown above on a page - say at http://bitdoti.com/sl-test.php and call it from in-world via the script shown (adjusting the URL, of course)? If I can get that far along, my next task would be to learn enough PHP to be able to read/write a MySQL table from the web page. I have a few interesting ideas in mind - some are along the lines of dynamically building and executing scripts, other have to do with being able to have persistant storage in the MySQL database. And, I have a somewhat novel and mind-blowing idea that I've been carrying around that I initially developed for a company that didn't make it through the dot-com-bubble-bursting days. (They went out and secured $45 million in venture capital to fund the development of this, which I never saw a single penny of.  ) Anyway, I just need to be able to actually get something to and from a web site from in-world as a starting point - I think I can learn enough PHP to figure out the rest of it, if I can make that happen. And thank you for posting that little php code blip there - everyone else seems to just assume that someone knows what to do on the web side of things. That's the first "clue" I've ever seen posted about it..
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
php
12-23-2006 22:10
Recently I've been learning php and catching on pretty quick. But my problem seems to be in the in game scripting.
Currently my project sends and recieves information in game to my server via a php script which talks to the sql database.
If you have any questions or need help with your project I'll do what I can, but when it comes to the in game scripting I really suck.
|