I heard the best method to share session across multiple domains on same server is to use custom php session handler. (ie, domain name different like abc.com, xyz.com but single application.)
But after i tried it, even custom php session handler that using SAME DATABASE ON 1 SERVER can't share session, when i tried to read cookie value from different domain.
Here's my custom session handler, Please kindly check or fix if something missing here. because i've tried it for a week now. can't get it to work
SESSION_INCLUDE.PHP - <?php
-
-
// config
-
$m_host = "localhost"; //MySQL Host
-
$m_user = "db_user"; //MySQL User
-
$m_pass = "db_pass"; //MySQL Pass
-
$m_db = "db_name"; //MySQL Database
-
$table = "sess_data";
-
-
$session_expire = 600; // Session expire time, in seconds (minutes * 60 = seconds)
-
-
$gc_probability = 100; // Probability that the garbage collection function will be called. 50% chance by default
-
-
ini_set("session.gc_probability",$gc_probability);
-
-
/* Open function; Opens/starts session
-
-
Opens a connection to the database and stays open until specifically closed
-
This function is called first and with each page load */
-
-
function open ($s,$n) // do not modify function parameters
-
{
-
global $session_connection, $m_host, $m_user, $m_pass, $m_db;
-
$session_connection = mysql_pconnect($m_host,$m_user,$m_pass);
-
mysql_select_db($m_db,$session_connection);
-
return true;
-
}
-
-
/* Read function; downloads data from repository to current session
-
-
Queries the mysql database, unencrypts data, and returns it.
-
This function is called after 'open' with each page load. */
-
function read ($id) // do not modify function parameters
-
{
-
global $session_connection,$session_read,$table;
-
$query = "SELECT data FROM `$table` WHERE id=\"{$id}\"";
-
$res = mysql_query($query,$session_connection);
-
if(mysql_num_rows($res) != 1) return ""; // must return string, not 'false'
-
else
-
{
-
$session_read = mysql_fetch_assoc($res);
-
$session_read["data"] = base64_decode($session_read["data"]);
-
return $session_read["data"];
-
}
-
}
-
function write ($id,$data) // do not modify function parameters
-
{
-
if(!$data) { return false; }
-
global $session_connection, $session_read, $session_expire, $table;
-
$expire = time() + $session_expire;
-
$data = mysql_real_escape_string(base64_encode($data));
-
if($session_read) $query = "UPDATE `$table` SET data=\"{$data}\", expire=\"{$expire}\" WHERE id=\"{$id}\"";
-
else $query = "INSERT INTO sess_data SET id=\"{$id}\", data=\"{$data}\", expire=\"{$expire}\"";
-
mysql_query($query,$session_connection);
-
return true;
-
}
-
function close ()
-
{
-
global $session_connection;
-
mysql_close($session_connection);
-
return true;
-
}
-
function destroy ($id) // do not modify function parameters
-
{
-
global $session_connection,$table;
-
$query = "DELETE FROM `$table` WHERE id=\"{$id}\"";
-
mysql_query($query,$session_connection);
-
return true;
-
}
-
function gc ($expire)
-
{
-
global $session_connection,$table;
-
$query = "DELETE FROM `$table` WHERE expire < ".time();
-
mysql_query($query,$session_connection);
-
}
-
// Set custom handlers
-
session_set_save_handler ("open", "close", "read", "write", "destroy", "gc");
-
-
// Start session
-
session_start();
-
?>
// MySQL Database Table - create table sess_data (
-
id2 int not null auto_increment,
-
id text not null,
-
data text,
-
expire int not null,
-
primary key(id2)
-
);
2 4308
What you've done is just change the location of where PHP stores information. I don't see any code that tells it to share this across multiple domains.
I'd go back to where you 'heard' about this and ask them what else you need to do different.
If I had to guess, I'd guess that your read would now need to look up the record with something other-than $id. It has to be a custom id that YOU makeup for your clients. That PHP id you're currently using is issued by PHP and PHP does not share that ID between domains.
Cheers,
Dan
"I don't see any code that tells it to share this across multiple domains."
because it's still on testing phase i just use firefox addon to manually change the ssid cookie value myself.. so the value of the session is same with the old domain.. no problem with that. & on real life i can just pass that old session id from old domain to new domain using $_GET
Sign in to post your reply or Sign up for a free account.
Similar topics
by: George Hester |
last post by:
In one Application (2) the client is redirected to a Logon ASP in a different Application (1). A Session Variable is made in Application 2 which needs to be recognized in Application 1. Can I do...
|
by: Le |
last post by:
Hello
I was wondering if there was a way to keep a user's session info across multple domains
For example, company A owns website www.a.com and www.b.com. A user logs into www.a.co
and later...
|
by: Darren Oakey |
last post by:
G'day -
is there anyway of sharing the Session data across two different ASP.Net
projects? Basically, I'm jumping from a page in one to a page in another,
and I'd like to have the data flit...
|
by: eSapient |
last post by:
My objective was to implement a 'Wait' page by using a combination of
an asynchronous call and a Session variable to signal the end of the
wait.
My first page has:...
|
by: Jim Tilson |
last post by:
I'm having a problem with Session ID being duplicated across multiple IE
windows.
I edited the web.config for my ASP.net web application to display trace
information on the page.
I open an IE...
|
by: Nayana Thara |
last post by:
We have a web site where we have asp and asp.net.
how can we share session data b/w the two environments.
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4. I have two domains -- www.mydomain1.com and
www.mydomain2.com. Both point to the same IP address. I have two
pages on that IP -- first.php
<?php
session_start();...
|
by: BDE Consulting |
last post by:
I am going crazy. This has been a problem now for over a year and I
have yet to figure out what is causing it.
I have a single server that is running multiple domains. For this
example I will...
|
by: rajiv07 |
last post by:
Hi to all
I am wondering how do i share the session across multiple Domains.Suppose i have set session in example1.com and i want to access the session in example2.com which is set in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |