ejectamenta
ejectamenta

Reputation: 1087

Cant get session working with ajax request

I have a simple file to set a session variable

<?php
   session_start();

   $_SESSION['my_name'] = "dave";

?>

and a simple file to see the stored variable

<?php
   session_start();

   echo $_SESSION['my_name'];
?>

if I call the file in the browser the session value is displayed correctly but if I make a ajax call using for example using http://requestmaker.com/ or https://www.hurl.it/ then the body response is blank. I can't see what is going wrong here its driving me nuts.

Any ideas

Cheers

Dave

Upvotes: 0

Views: 184

Answers (2)

ejectamenta
ejectamenta

Reputation: 1087

Its inappropriate to use third party http-request sites and still expect the session variables to be valid since the request is then coming from a different domain to your server.

Upvotes: 0

Luis Deras
Luis Deras

Reputation: 1269

You're trying to watch $_SESSION['user_name'] variable when you saved the $_SESSION['my_name']. variable

Correct one of the identifiers.

Upvotes: 1

Related Questions