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

0 favourites
  • 1 posts
From the Asset Store
Paypal PHP Supports multiple platforms, Web/html5 Android, IOS. (Including storing transaction data)
  • 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):

    <?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.";
        }
    ?>
    [/code:x3hft4n9]
    
    When I run this script in my browser it works perfectly:
    [ul]
    [li] First: "Variable has been set"[/li]
    [li] Refresh: "Success!"[/li][/ul]
    
    But when I create a button in Construct 2 which sends an AJAX request to that session_test.php script the following happens:
    [ul]
    [li] First: "Variable has been set"[/li]
    [li] Refresh: "Variable has been set"[/li][/ul]
    
    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?
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)