Forum Moderators: coopster
1. User views normal site on server A
2. User follows a link to a page that requires him to be logged on.
3. PHP on the protected page discovers he is not logged on and redirects him to a login form on server B, the secure SSL server.
3. User completes login form and gets redirected back to the protected page on server A.
4. The protected page now lets him view its contents.
The problem is how do I let server A know that the user successfully logged in on server B? :o
They have different hosts, so I don't think I can use sessions. And cookies would be way to insecure.
Any suggestions?
$id = session_id();
$lifetime = get_cfg_var("session.gc_maxlifetime");
function SessionStart($session_save_path,$session_name) {
mysql_pconnect("host","username","password") or die("Can't connect to MySQL server!");
mysql_select_db("database") or die("Can't select MySQL sessions database");
}
function SessionEnd() {
return 1;
}
function SessionRead($id) {
$result = mysql_query("SELECT data FROM sessions WHERE sessionid='".session_id()."' AND expires>".time());
if($result && mysql_num_rows($result)) {
$var = mysql_fetch_row($result);
$temp = $var[0];
return $temp;
}
else {
global $whatever;
global $lifetime;
$expires = time()+$lifetime;
$result = mysql_query("INSERT INTO sessions (sessionid,expires,data) VALUES('".session_id()."','$expires','$whatever')");
return "";
}
}
function SessionWrite($id,$whatever) {
global $lifetime;
$expires = time()+$lifetime;
$result = mysql_query("UPDATE sessions SET expires='$expires',data='$whatever' WHERE sessionid='".session_id()."' AND expires>".time());
}
function SessionDestroy($id) {
$result = mysql_query("DELETE FROM sessions WHERE sessionid='".session_id()."'");
}
function SessionGarbageCollect($lifetime) {
$result = mysql_query("DELETE FROM sessions WHERE expires<".time());
}
?>
You'll have to do this to decode the session variables on subsequent pages:
session_start();
session_decode($temp);
As far as table structure, this works for me:
sessionid - varchar(32), primary key
expires - int(11)
data - text
Not sure if I want to go down this road or not though. Seems an overly complex solution somehow.
just using include to grab the page from server A
Yeah that would be the easiest solution... but (there is always a 'but' isn't there?) server B is a shared server with a shared server certificate and a common url.
i.e. The urls look like https:/secure.acommerceserver.com/my_username/ rather than http:/www.my_username.com
So the resulting pages would have ugly, off-site urls. Which would no doubt confuse my users (who are non-technical doctor types).