javascript - $_SESSION variable empty when accessing from AJAX on different port -


this question has answer here:

i have created site has php side runs on port 80 (index.php), when login sets session variable userid.

i click link takes me port 8080, javascript file carries out node.js processes (live.html).

from node.js client file (live.html) request userid file called getusersession.php echos out userid session.

when run ajax request (live.html), returns session userid empty if manually insert url web browser echos user session (http://localhost:8080/getusersession.php).

i have dumped array response , tells me $_session variable empty.

i attempted returned plain text string test - returns no problem, seems issue accessing session variable different port, , not actual ajax call itself.

update: how resolved problem.

i added index.html file:

$.getjson("`http://localhost:80/getusersession.php?callback=?`", { username: "lazy"}, function(json){       username = json.message;     }); 

and added following php file:

<?php session_start();//start session $user2 = (string)$_session['username']; $callback = $_get["callback"]; $user = $_get["username"];  if($user == "lazy") {   $response = array("message" => $user2); } else {   $response = array("message" => $user2); }  echo $callback . "(". json_encode($response) . ");"; 

still needs tidied works. help

when make request php browser, session created linked browser. when make request php using node.js, new session created between php , node.js request because node.js not same client web browser.

one workaround pass session token information node.js node.js can request php file same client, i'm not sure if that's can php out-of-the-box. coldfusion it's simple passing cftoken , cfid if you're using default settings session management.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -