MasterACE14 Posted December 13, 2011 Share Posted December 13, 2011 Good Day, I'm using the following example script from http://php.net/manual/en/function.session-set-save-handler.php which I have placed in session-handler.php and is included at the top of my index.php file. I have multiple domain names for the same website, so naturally when a person logs into the site, I would like the session to be active across all the domains instead of them having to login again if say they go from mysite.com to mysite2.com. session-handler.php <?php function open($save_path, $session_name) { global $sess_save_path; $sess_save_path = $save_path; return(true); } function close() { return(true); } function read($id) { global $sess_save_path; $sess_file = "$sess_save_path/sess_$id"; return (string) @file_get_contents($sess_file); } function write($id, $sess_data) { global $sess_save_path; $sess_file = "$sess_save_path/sess_$id"; if ($fp = @fopen($sess_file, "w")) { $return = fwrite($fp, $sess_data); fclose($fp); return $return; } else { return(false); } } function destroy($id) { global $sess_save_path; $sess_file = "$sess_save_path/sess_$id"; return(@unlink($sess_file)); } function gc($maxlifetime) { global $sess_save_path; foreach (glob("$sess_save_path/sess_*") as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); } } return true; } session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); session_start(); ?> The script above doesn't appear to be throwing any errors, and I can login like normal but it doesn't seem to be saving the sessions at all. So I still have to login to each separate domain. Any ideas? Thanks, Ace Quote Link to comment Share on other sites More sharing options...
ebruggema Posted December 13, 2011 Share Posted December 13, 2011 http://www.jotlab.com/2008/04/08/howto-get-cookies-across-subdomains-php/ this website can help you getting it tru Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2011 Share Posted December 13, 2011 Is your problem actually for subdomains (part of the thread's title) or domains? The solution for subdomains is different from that of different domains. In your previous thread, someone mentioned (in great detail) that the session id WILL NOT BE propagated between different domains by the browser using a session id cookie or by php's transparent sid management on the end of the URL and that you would need to propagate the session id on the end of the URL across different domains yourself. Did you do this when you navigated between your different domains? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 14, 2011 Author Share Posted December 14, 2011 you would need to propagate the session id on the end of the URL across different domains yourself. Did you do this when you navigated between your different domains? Ah ok, I shall give that a go. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.