How do I use sessions in PHP and Constrcut's AJAX?

Get help using Construct 2

Post » Mon Oct 23, 2017 9:34 am

Hello :)

I have a problem with sessions in PHP together with Construct 2.

I use the following PHP script (credits
Code: Select all
   header('Access-Control-Allow-Origin: *');

        echo "Session variable exists<br/>";

            $_SESSION['test'] = "Success!";
            echo "Variable has been set, refresh the page and see if stored it properly.";
            echo $_SESSION['test'];
        echo "No session variable has been created.";

When I run this script in my browser it works perfectly:
  • First: "Variable has been set"
  • Refresh: "Success!"

But when I create a button in Construct 2 which sends an AJAX request to that session_test.php script the following happens:
  • First: "Variable has been set"
  • Refresh: "Variable has been set"

It seems like there's always recreated a new session. I also tried to export my game and to upload it onto my webserver - same result. Does it have something to do with Construct 2?
Posts: 13
Reputation: 528

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest