First of all let me illustrate what I mean.
For instance if I open google.com on my browser and I login, and then I open youtube.com or gmail.com or any other Google site, I automatically get logged in based on my google.com login details.
Now I need to achieve the same thing. I have 2 sites running the same database, infact one is a sub-domain to the other. Let say mainsite.com and sub.mainsite.com now I have a hyper-link that directs a user to sub.mainsite.com from mainsite.com and I don't want the user to login again on sub.mainsite.com I just want to get the user login id from mainsite.com and automatically login the user on sub.mainsite.com. Though for now am running this on my local WAMP server. I haven't tried it online.
Now I create a page on mainsite.com called master.php which gets the logged in user and echo the id. And if I type the address to the page on my browser, it works fine. But now I want to retrieve the id from master.php on the index page of sub.mainsite.com but instead I get an error of undefined index 'user'.
I know session details are protected from other sites but I guess there should be a way out of this.
master.php
<?php
$home = $_SERVER['DOCUMENT_ROOT];
ini_set('session.save_path', realpath($home));
session_start();
$id = $_SESSION['user'];
echo $id;
?>
sub.mainsite.com/index.php
<?php
function getCURL($url){
$ch = curl_init();
$timeout = 60;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$data = getCURL('http://mainsite.com/master.php');
echo $data;
?>