How to store and fetch username from URL

Get help using Construct 2

Post » Wed Nov 13, 2013 7:35 am

Hi guys,

     I am having a problem in getting data.

If the user enter's his name in the text-box and clicks submit button that username has to store in URL and how can i fetch that URL username into a further levels text-box's.
B
3
Posts: 18
Reputation: 211

Post » Wed Nov 13, 2013 10:38 am

EDIT:

I just realised you asked for an option to place info in another text box ...

Within construct you ca easily stuff something in a global variable and use it later somewher else ...


As to data settting and retrieval elsewhere, outside of your game ..

I use php scripting for that

you need:web server,php   and/or mysql database

Ajax post url with parameters (ie: username, pass, safety code, page request, etc)

That url is your PHP page which needs to use the variables from the $_POST['username'] which its receiving fromyour construct 2 application.   
For a user system this should be checked in php versus the mysql table.

The php page should should echo some sort of result, I use the tokenat for that, ie:

<?php

....process constructs 2 ajax call and give results....

echo "success|you have logged in";

?>

in Construct fetch the php echo from the ajax call with AJAX.LastData.

I then do: if tokenat(AJAX.LastData, 0, "|")   (check string before pipe sign) check if its "success"


If the user entered wrong info, you could have php echo "failed|incorrect pass";

and have it display the second bit after the pipe to relay info what was wrong :) (wrong pass)

Hope that makes it a bit more clear.



lennaert2013-11-13 10:44:18
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Wed Nov 13, 2013 12:34 pm

hi lennaert,
             Thanks for the help and small correction the thing is like i need to post the username to to URL and that URL i need to fetch to a textbook

Ex)I am entering into a site through login and need to get like below link and is there any way in construct2 to change URL based on login as shown below.

     www.v2kkindom.com/?username=v2k

How can i post the username to URL and that URL how can see in a textbox ?
B
3
Posts: 18
Reputation: 211

Post » Wed Nov 13, 2013 3:48 pm

So you want the exported application, to be able to catch paramters from the URL which was used to open the web application ??

I dont think there is anything native for that in Construct 2, might be a good addition though. Perhaps through one of the plugins where you can execute javascript.

I believe in javascript you would need to access the location.search, should give you all the parameter keys and values from the URL in a long string.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Sat Feb 01, 2014 5:42 pm

Use the Browser object

With the QueryParam expression, you can:
"Return a query string parameter by name. For example, if the URL ends with index.html?foo=bar&baz=wan, QueryParam("foo") returns bar and QueryParam("baz") returns wan."

With the Go to URL action, you can direct the browser to a new URL (if needed).



B
8
S
3
G
1
Posts: 8
Reputation: 1,225

Post » Sun Feb 02, 2014 2:22 am

@v2k, you can also do it using AJAX and php.
I made an app that is accessed through a website where you have to login (using .htaccess) and then pass the username into the Contstruct 2 app using AJAX to call a php script that just echos the username.
B
94
S
33
G
20
Posts: 438
Reputation: 17,615


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests