[SOLVED] Get $_SESSION variable from the php page it is on.

  • I have a login system that loads a .php page and that displays that you are logged in at the top of the screen like this..

    Hey, <?php echo $_SESSION['user_name']; ?>. You are logged in.

    Then below that on the page will be the whole construct2 bit. (the canvas)

    So construct2 has nothing to do with the login system I use and it will be on a .php page.

    QUESTION:

    How do I grab that $_SESSION variable and load it into a global variable in Construct2?

    Thanks.

  • Set a javascript variable in the web page, and fetch it using the browser object's execute custom javascript.

  • All i have on the page now (besides the construct2 portion) is:

    Hey, <?php echo $_SESSION['user_name']; ?>. You are logged in.

    Not sure how to add javascript to the page but something like..

    <script>

    var currentuser = $_SESSION['user_name'];

    </script>

    Would that work? Or am i totally off?

    Never done any javascripting..

  • All i have on the page now (besides the construct2 portion) is:

    Hey, <?php echo $_SESSION['user_name']; ?>. You are logged in.

    Not sure how to add javascript to the page but something like..

    <script>

    var currentuser = $_SESSION['user_name'];

    </script>

    Would that work? Or am i totally off?

    Never done any javascripting..

    <html>

    mehhh

    <body>

    <javascript>

    var username = "<?php echo $_SESSION[username]; ?>";

    </javascript>

  • I seeee. So you can include php into the javascript.

    Cool bud. Cheers

  • Just as long as your index file has a .php extension (simply change .html to .php and make sure your links to it are updated too.)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • lennaert

    Let me bother you some more maestro..

    I get the concept of what you are saying but since i only just learned a bit of php and now i have to get into javascript i am finding it hard to do.

    In Construct2 i should basicly do something like this?

    System>Set variableX to "ExecJS('username')" ?

    Is this correct? Or is it not ExecJS I should be using? Perhaps EvalJS?

    Completely lost it now..

  • set var = Browser.ExecJS("window.MyUsername")

    in the index file I have :

    <script>

    var MyUsername = "Lennaert";

    </script>

  • Hold on.. I initially asked if <script> was the way to go but you corrected me it should be <javascript>..

    Now you use <script>?

    Confusing haha

    Cheers though man. You rule

  • Hold on.. I initially asked if <script> was the way to go but you corrected me it should be <javascript>..

    Now you use <script>?

    Confusing haha

    Cheers though man. You rule

    whahaha

    well ... it used to be javascript ... stuff changed, habits die hard

  • Works like a charm by the way.

    Awesomeness!

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