0

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

4
  • 2
    Are you sure the 2 sites mentioned keep session cookies? Have you tried it with a jQuery call or anything else you would like? Commented Mar 26, 2016 at 0:52
  • 2
    You can't control / manage sessions from other sites via AJAX like that. Commented Mar 26, 2016 at 0:52
  • 2
    CORS: developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS Commented Mar 26, 2016 at 0:56
  • Ah I see, because the request from then coming from another domain eg requestmaker.com the session variables were invalid, guess I should have considered that, my excuse is that it's 2am! Commented Mar 26, 2016 at 1:02

2 Answers 2

1

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

Correct one of the identifiers.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.