Re: Shared session ? (frames application)
| From: | Torsten Roehr | Date: | Sun, 25 Apr 2004 17:29:35 +0000 |
| Subject: | Re: Shared session ? (frames application) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184574@lists.php.net to get a copy of this message | ||
This is possible without problem. Just start your session in every script
and forward the session id from your frameset (which is probably the first
page to be called by the user) to each frame:
frames.inc
----------
<?
// start session here
// ...
<frameset cols="350,*" rows="*" frameborder="1">
<frame src="left.php?<?= SID; ?>" name="left"
frameborder="1">
<frame src="main.php?<?= SID; ?>" name="main"
frameborder="1">
</frameset>
?>
Make sure to put the session start code at the top of EVERY page.
Regards, Torsten
"Richard A. Devenezia" <radevenz@ix.netcom.com> wrote in message
news:20040425150925.67894.qmail@pb1.pair.com...
> I am wondering if it is possible to let two or more scripts share a common
> session id ?
> I am guessing not, but would like to be proved wrong.
>
> This is the situation cut down about as small as I could make it.
> Five files: index.php, login-form.inc, frames.inc, left.php, main.php
>
> index.php
> -----
> <?
> session_name('cesh');
> session_start();
> $function = $_POST['function'];
> if (!isset($function) || $function='') {
> include "login-form.inc"; die;
> }
>
> file://test, user always valid
> function validuser () { return true; }
>
> if ($function == 'login') {
> if (!validuser($_POST['user'], $_POST['pass'])) {
> include "login-form.inc"; die;
> }
> }
> $_SESSION['user'] = $user;
> $_SESSION['foo'] = 'bar';
> include "frames.inc";
> ?>
> -----
>
> login-form.inc
> -----
> <html><body>
> <form method=POST>
> user <input type=text name=user><br>
> pass <input type=text name=pass><br>
> <input type=submit value=Login>
> <input type=hidden name=function value=login>
> </body></html>
> <? die; ?>
> -----
>
> frames.inc
> -----
> <?
> // get var used to pass session id to left and main scripts
> $sid = SID;
> $src = <<<EOF
> <frameset cols="350,*" rows="*" frameborder="1">
> <frame src="left.php?$sid" name="left" frameborder="1">
> <frame src="main.php?$sid" name="main" frameborder="1">
> <noframes>
> <body bgcolor="#FFFFFF">
> <p>phpMyAdmin is more friendly with a <b>frames-capable</b>
> browser.</p>
> </body>
> </noframes>
> </frameset>
> EOF;
>
> $src = str_replace("\n", "", split ( "\n", $src ));
> ?>
> <html>
> <script type="text/javascript">
> <!--
> <?
> foreach ($src as $line)
> { echo "document.writeln('${line}');\n"; }
> ?>
> file://-->
> </script>
> <noscript>
> <?
> foreach ($src as $line)
> { echo ${line} . "\n"; }
> ?>
> </noscript>
> </html>
> -----
>
> left.php
> -----
> <html><body>
> Left<br>
> Is it possible to access (read/write/set/unset) the variables of session
> <?=$_GET['cesh']?><br> ?
> </body></html>
> -----
>
> main.php
> -----
> <html><body>
> Main<br>
> Is it possible to access (read/write/set/unset) the variables of session
> <?=$_GET['cesh']?><br> ?
> </body></html>
> -----
>
> --
> Richard A. DeVenezia