Set php session variable using ajax on electron


#1

Hi,
I want to build an electron app with PHP inside it, but suddenly I need to set PHP session variable to get some parameters from user log in, but it’s returns a strange thing for me.

this is my ajax script

$("#button").click(function(){
     $.ajax({
            url: "http://localhost/mysite/index.php",
            data: "uname=" + uname,
            type: "POST",
            success: function(x){
                   alert(x); //it's returns my uname
            }
     })
})

this is my php to get the data and set session (index.php)

session_start();
$uname = $_POST["uname"];
$_SESSION["uname"] = $uname;
echo $_SESSION["uname"];

my javascript x variable is returns my uname, but when I tried to call another ajax to check my session, it’s nothing on x that’s mean the php session just work on one ajax and reset on different ajax…

this is how i check my session

$.ajax({

url: “http://localhost/mysite/index.php”,
data: “uname=” + uname,
type: “POST”,
success: function(x){
alert(x); //it’s returns my uname
}
})


#2

please ignore my session check, I want to edit it before but my mistake it is posted.