Reputation: 381
If a person logs into a website (Website A) and this website creates session variables, could another website (Website B) make a cURL call to a PHP routine on Website A that would send back to Website B a json variable with Website A's session variables?
If so, how can I accomplish this?
This is the scenario I have in mind:
Is it doable through cURL?
Thanks.
Upvotes: 0
Views: 637
Reputation: 381
As my websites are NOT in the same server, this is what I had to do to make it work (without memcache). This is not the most elegant solution but this is how I made it work, i.e., how to send to Website A the contents of the session variables of Website B:
header()
to Website B. The requesting php in Website A sends its URL as part of the query string so Website B knows where to send its answer.session_id()
and sends it back to Website A through an auto-submit post form.Note: without the session ID, Website B sends an empty session variable to Website A.
Upvotes: 1
Reputation: 107
Haven't tried this so I have no idea if it would work however my best guess to get something similar to what you'd want is as follows.
Assuming both websites are on the same server you could manually set the session_id() and then keep track of this value. You then send this ID string to Website B and call session_id() there too with the same ID.
http://php.net/manual/en/function.session-id.php
If your Websites aren't on the same servers then you'd need to edit your php.ini and connect your session store to a service like memcache.
So for example.
Website A:
session_id('test');
$_SESSION['hello'] = "hello world\n";
Website B:
session_id('test');
echo $_SESSION['hello'];
Obviously you'd need to do a lot more work than above as you need to generate unique IDs for each user / request.
Upvotes: 2