Page 1 of 1

How to GET (query string parameters)

Posted: Mon Jan 26, 2015 12:08 pm
by ChrisMukrow
Is it possible to make a GET in Livecode, http://url.com/?id=10 (result: id=10), couldn't find it in the docs. Like $_GET in php?

Thanks,
Chris

Re: How to GET (query string parameters)

Posted: Mon Jan 26, 2015 3:17 pm
by Klaus
Hi Chris,

not being an internet expert, but isn't this a simple as:
...
put url "http://url.com/?id=10" into tResultData
...
Or if you prefer IT:
...
GET url "http://url.com/?id=10"
...
?


Best

Klaus

Re: How to GET (query string parameters)

Posted: Mon Jan 26, 2015 3:26 pm
by ChrisMukrow
Hi Klaus,

My message was a bit vague, sorry for that. The idea is: when you use php $_GET["id"] on this url http://url.com/?id=10, you get the variable from id (which is 10). I want to use this so I can combine html with Livecode.

Hope this makes it clear, thanks for your help!

Re: How to GET (query string parameters)

Posted: Mon Jan 26, 2015 5:35 pm
by Klaus
Hi Chris,

aha, but still not sure if this is now a real internet/url issue or a "simple" text chunk problem? :D
If the latter, you need to parse the string by yourself, maybe set the itemdelimiter to ? first?


Best

Klaus

Re: How to GET (query string parameters)

Posted: Mon Jan 26, 2015 10:11 pm
by jacque
If you're writing a server script, you can use $_GET or $_GET_RAW. There are a number of other "$_" functions in the dictionary that might be what you want too.

If you are writing a desktop app, the environment variables are available via the "$" function, but it doesn't seem likely that an app would be receiving URL requests. If the app is generating the URL then it already knows the values of the parameters.

Re: How to GET (query string parameters)

Posted: Tue Jan 27, 2015 9:35 pm
by ChrisMukrow
Thanks Klaus and Jacque, I will try it with the itemdelimiter, thats good enough for now. And Jacque your right, it's an unlikely scenario. But I want to use precreated html files in app and combine these with native features.

Re: How to GET (query string parameters)

Posted: Tue Jan 27, 2015 10:34 pm
by jacque
Okay, I see. The usual way to parse out query string values is to split the query portion of the URL into an array like this:

Code: Select all

put char offset("?",tURL)+1 to -1 of tURL into tQuery
split tQuery by "&" and "="
Now you have an array with the variables as keys and the elements as their values.

Re: How to GET (query string parameters)

Posted: Fri Jan 30, 2015 11:35 am
by ChrisMukrow
Thanks Jacque! Will give it a try.