How to store and fetch username from URL

0 favourites
  • 6 posts
From the Asset Store
Fetch Quest
$19.99 USD
Fetch Quest 1 music pack is a collection of 10 in-game music loops.
  • 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.

  • 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.

  • 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 ?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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).

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)