Transfering session data between servers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DudeBori82
Forum Commoner
Posts: 26
Joined: Thu Nov 18, 2004 10:09 am
Location: Florida

Transfering session data between servers

Post by DudeBori82 »

In the process of navigating through my site, the user travels between two servers. As they navigate, session arrays store the data I need, but it's lost when they go to the new server. What is the best way to "copy" or "transfer" data to a new session on the other server. Or possibly transfer the session between servers. (The data is stored in arrays, so using POST method is difficult and tedious.)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a ghetto way is to transfer the data behind the scenes.. either posting it (recommend encryption) using one of the request functions, or through the database (ideal) if the database is accessible between the servers. However, the session id may be a pain to transfer, if they truly are different domains...
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

it shouldnt be difficult to post the data to the other server at all if you use the right methods.


$data = serialize($_SESSION);

now post $data to the other server


you wil need to restore the data like

$_SESSION = unserialize($_POST['data']);

you may need to use stripslashes if magic quotes is on.

and like feyd said, encrypt it.
Post Reply