Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Configure each site individually:</p> <pre><code>&lt;?php $cfgsession['file'] = "../sessions_global.txt"; $cfgsession['keepalive'] = 7200; ?&gt; </code></pre> <p>To make multiple sites share sessions, let them use the same <code>$cfgsession['file']</code>. Include a session from one site in a request to another domain (perhaps as recommended by Jack), and as long as you don't catch them making their request in another browser or whatever (please do <i>something</i> to inhibit session hijacking), let them specify a session with $_GET. For example:</p> <pre><code>include ("../session.php"); if (isset($_COOKIE['session'])) session_begin($_COOKIE['session'], $_SERVER['HTTP_USER_AGENT'] . "+" . $_SERVER['HTTP_ACCEPT_CHARSET'], $_SERVER['REMOTE_ADDR']); else session_begin("", $_SERVER['HTTP_USER_AGENT'] . "+" . $_SERVER['HTTP_ACCEPT_CHARSET'], $_SERVER['REMOTE_ADDR']); setcookie("session", session_identity(), 0); </code></pre> <p>And then just roll your own session_ functions:</p> <pre><code>&lt;?php function session_begin($mysession = "", $key = "", $client = "") { global $cfgsession; if (!preg_match("/^[a-z0-9]{32}$/i", $mysession)) $mysession = md5(microtime()); $error = false; $client = trim($client); $key = trim($key); $cfgsession['returning'] = false; if ($chandle = @tmpfile()) { if ($shandle = @fopen($cfgsession['file'], "rb")) { flock($shandle, LOCK_SH); fputs($chandle, $mysession . " " . time() . " $" . $client . " $" . $key . "\n"); while (!feof($shandle)) { $sline = explode(" ", trim(fgets($shandle)), 4); if ($sline[1] &gt;= (time() - $cfgsession['keepalive'])) { if (($sline[0] == $mysession) &amp;&amp; ($sline[3] == "$" . $key)) { $cfgsession['client'] = substr($sline[2], 1); $cfgsession['returning'] = true; } elseif (count($sline) &gt; 2) fputs($chandle, implode(" ", $sline) . "\n"); } } fclose($shandle); fseek($chandle, 0); if ($shandle = @fopen($cfgsession['file'], "cb")) { if (flock($shandle, LOCK_EX)) { ftruncate($shandle, 0); $cfgsession['count'] = 0; while (!feof($chandle)) { $cline = trim(fgets($chandle)); fputs($shandle, $cline . "\n"); $cfgsession['count']++; } } else $error = true; fclose($shandle); } else $error = true; } else $error = true; fclose($chandle); } else $error = true; if (($cfgsession['returning'] == false) &amp;&amp; ($mysession == $cfgsession['session'])) { $cfgsession['returning'] = true; $mysession = md5(microtime()); } $cfgsession['session'] = $mysession; if ($error) return -1; else return 0; } function session_count() { global $cfgsession; return $cfgsession['count']; } function session_client() { global $cfgsession; return $cfgsession['client']; } function session_id() { global $cfgsession; return $cfgsession['session']; } function session_index() { global $cfgsession; $index_return = array(); if ($uhandle = @fopen($cfgsession['file'], "rb")) { flock($uhandle, LOCK_SH); while (!feof($uhandle)) { $uline = explode(" ", trim(fgets($uhandle)), 4); foreach ($uline as &amp;$value) { if ($value[0] == "$") $value = substr($value, 1); } if (count($uline) &gt;= 2) $index_return[] = $uline; } fclose($uhandle); } return $index_return; } function session_returning() { global $cfgsession; return $cfgsession['returning']; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload