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 https://stackoverflow.com/a/9943142/6423282):
Code: Select all
<?php
   header('Access-Control-Allow-Origin: *');
    session_start();

    if(isset($_SESSION)){
        echo "Session variable exists<br/>";

        if(!isset($_SESSION['test'])){
            $_SESSION['test'] = "Success!";
            echo "Variable has been set, refresh the page and see if stored it properly.";
        }else{
            echo $_SESSION['test'];
        }
    }else{
        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?
B
9
S
2
Posts: 10
Reputation: 497

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests