0

I am a newbie in PHP, I know how to set a session variable in my own website. I am trying to do this task where I need to set a session variable on another website that redirects to the login page on my website. Is it possible? If the question is still ambiguous, here is a better explanation.

My website is on server A Another website is on server B A page on server B redirects the user to a page on server A. This page checks if the login details are correct. If they are, the page on server A sets a session variable. However, when it redirects to server B after setting the session variable. The page on server B directs it back to server A notwithstanding the session set.

Here is the code if you need to see it

if(!isset($_SESSION["user"]))
{
header("Location: http://serverA.com/login.php?w=serverB.com");
}
elseif (isset($_SESSION["user"]))
{
//do something
}
Engr Atiq
  • 163
  • 2
  • 16
  • Sharing sessions between sites, although likely possible, is not really recommended. You would be better off finding a PHP SSO implementation. The only way to get sessions talking like that would be if both servers had access to the same session files in the temp directory (both websites on same server) or using a database session implementation and both sites/servers having access to the same database. – Jonathan Kuhn Sep 13 '16 at 16:38
  • It is not easy, but possible. Read related: http://stackoverflow.com/questions/13806701/secure-and-flexible-cross-domain-sessions http://stackoverflow.com/questions/1339984/cross-domain-php-sessions http://stackoverflow.com/questions/14611545/preserving-session-variables-across-different-domains – Alexey Chuhrov Sep 13 '16 at 17:38

1 Answers1

1

You are unable to share session data across more than one site/server, the only possible way that you could do this is by using a PHP script to POST the data or send the data by the header using Get (?=username)

To use Post, I'd suggest that you use CURL

To use Get, you could make the url that you used in the header() and add something like ?username=data or you could also make this into an ID so that the second server or website can check it with a Database.

Other than these two, I'm unable to think or find anything else.

Community
  • 1
  • 1
FluxCoder
  • 1,266
  • 11
  • 22