user2994429
user2994429

Reputation: 105

PHP $_Session transfer across domain

Yes, I know this has been asked a thousand times.. But, I've still been unable to find any specific fix that seems to work every time. I've tried many of the fixes people have suggested and I'm still having the same issue as before.

So, I run a server with a setup of multiple domains. They're all on the exact same server, and there is no transfer between servers here.

carnal.ueteribus.com <--- The Cookie is read and displayed here.
www.ueteribus.com <--- The login script is hosted here.

Basically those are the only two domains, and I'm trying to get the information from WWW to transfer to Carnal. Which is easier said than done.

Currently I've been trying to use
ini_set('session.cookie_domain', '.ueteribus.com');

Which hasn't worked, or maybe I have it programmed wrong. Anyways, any help would be very appreciated and if any additional information is required I am more than happy to provide.

NOTE: I do not have access to the PHP.ini, the company has denied such access.

session_name('LoginSession');
session_set_cookie_params(0, '/', 'ueteribus.com');
session_start();

I've also tried that
That seems to work in creating a named Cookie, but I couldn't figure out how to call it. My script wouldn't work anymore to call the actual login status, and I couldn't figure out how to fix it to ensure that this was even working.

<?php
session_set_cookie_params(0, '/', '.ueteribus.com'); 
session_start(); 

if (isset($_SESSION['error'])) {

echo $_SESSION['error'];    
}
?>

Upvotes: 0

Views: 179

Answers (2)

Sammitch
Sammitch

Reputation: 32232

The absolute first two things in your scripts need to be:

ini_set('session.cookie_domain', '.xxxx.com');
session_start();

in that order, and any session's begun before adding that code will become inaccessible.

This assumes that both domain1.xxxx.com and www.xxxx.com live on the same server and use the same instance of PHP. It is impossible to share PHP session data across servers without writing your own custom session handler.

If there are no other domains on the server you may want to simply set session.cookie_domain in your php.ini.

Upvotes: 1

Mahdi
Mahdi

Reputation: 9407

Maybe something like this:

session_name('shared-name-between-sub-domains');
session_set_cookie_params(0, '/', '.domain.com');
session_start();

Upvotes: 1

Related Questions