How do I get PHP Sessions to work with construct 2

0 favourites
  • 5 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Im currently using AJAX plugin to post to a server and then i start a session like this

    <?php

    session_start();

    $_SESSION['user'] = 'cat';

    ?>

    Then i go to a different layout in construct 2 and i post to a different php script on the same server like this

    <?php

    session_start();

    echo $_SESSION['user'];

    ?>

    I get nothing back. The session variable is empty . The variables are not saving from one script to another.

    Is this not going to work?

    Ive been toying with this for days

  • It should work, to PHP its all the same session.

    things to keep in mind:

    -Origin access, add: header('Access-Control-Allow-Origin: *'); to the top of your PHP file.

    -Ajax.LastData should have the result of your PHP Ajax request

    -Check developer console during preview: hit CTRL SHIFT J in Chrome, and check the network tab, it should show the direct results of your request.

  • hi,

    i have the same problem

    i have the header('Access-Control-Allow-Origin: *');

    but problem still there..

    if i open that php files with browser then work fine but if i use ajax in c2 The session variable is empty

    pugbreeder did you solve it ?

  • i export my project and it work fine !

    so the problem is with the preview but i dont know what is the problem !

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I need help for this to

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