0

I have multiple subdomains like domain1.example.com, domain2.example.com. I have central database for these subdomains; and i create session for each subdomain when i login (through ajax).

Now i want when i logout from any subdomain, then i logout from all the subdomains (session_destroy) where the session has been created. (I have the list of subdomains where session is maintained). Plz help how to logout from multiple subdomains using cURL.

I am using the following cURL code in loop for subdomains.

$url = 'http://' . $a_domain . ".localhost/panels/login?task=logout";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);                
$output = curl_exec($ch);
curl_close($ch);

Moreover when i directly run the $url in browser, it works and logout from that subdomain, but i want to work it in loop throug cURL. ??

The remote subdomain $URL logout code

public function logout(){
echo '<br>before destroy <br>'; 
print_r($_SESSION);
session_destroy();
echo'<br>after destroy <br>';
print_r($_SESSION);
}
Prisoner
  • 27,391
  • 11
  • 73
  • 102
Shaibi Rana
  • 29
  • 1
  • 6
  • So if you have list of all subdomains then why not just call all their urls one by one in a loop like you already mentioned? – Hanky Panky Jan 22 '13 at 06:34
  • yeah i am doing this i.e.calling the list of URL throug cURL to logout, but its not working (not working means when i goto the next or previous page, the session is still there, it must have been destroyed) – Shaibi Rana Jan 22 '13 at 08:02
  • Are you aware that you are able to set sessions/cookies up so they work across sub-domains under a single main domain? http://stackoverflow.com/questions/644920/allow-php-sessions-to-carry-over-to-subdomains. I'd be worried about how you are setting up these sessions over AJAX. – Prisoner Jan 22 '13 at 09:26
  • I have session.php file which start and set the session variables. When logging in, i get the list of subdomains; through ajax, i call that session.php file with post parameters (http://subdomain1.example.com/session.php) in loop. In this way calling session.php for every subdomain creates an independent session of each subdomain. – Shaibi Rana Jan 22 '13 at 09:35

1 Answers1

1

Something like

<?php

$domains=array();
$domains[]="a";
$domains[]="b";
$domains[]="c";
$domains[]="d";

foreach($domains as $d)
{
    $url = "http://".$d.".localhost/panels/login?task=logout";
    logout($url);
}

function logout($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);                
    $output = curl_exec($ch);
    curl_close($ch);
}

?>
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • Thanks for your reply...in the remote subdomain function where the cURL is sending request, i have printed the $_session before and after the session_destroy command, but the result is same.. is there something i miss in that function ....? – Shaibi Rana Jan 22 '13 at 09:10
  • public function logout(){ echo '
    before destroy
    '; print_r($_SESSION); session_destroy(); print_r($_SESSION); echo '
    after destroy
    '; print_r($_SESSION); }
    – Shaibi Rana Jan 22 '13 at 09:15
  • append it to your question – Hanky Panky Jan 22 '13 at 09:15