PHP Sessions in frames.... | | |
Hey all,
I have a website, which uses frames (I know, I know...). Left frame is
a navbar, with the main content in the right frame.
I can login using sessions on the right frame, giving "Thankyou, $name
(where $session(name) = $name etc - not got code available atm, so
thats not exactly right, but you get the gist...)
I use <body onLoad parent.leftframe etc to reload the left frame, which
checks to see if $name is blank, if it is, it displays a login link, if
its got text in, it displays "You are logged in as $name".....
Except I can't get my left frame to recognise that there is something
in $name, so it always displays the login link...
Am I missing something, or is there a limitation in php sessions with
regards to frames...
Thanks,
Ben | | | | re: PHP Sessions in frames....
BWGames wrote:
[color=blue]
> Hey all,
>
> I have a website, which uses frames (I know, I know...). Left frame is
> a navbar, with the main content in the right frame.
>
> I can login using sessions on the right frame, giving "Thankyou, $name
> (where $session(name) = $name etc - not got code available atm, so
> thats not exactly right, but you get the gist...)
>
> I use <body onLoad parent.leftframe etc to reload the left frame, which
> checks to see if $name is blank, if it is, it displays a login link, if
> its got text in, it displays "You are logged in as $name".....
>
> Except I can't get my left frame to recognise that there is something
> in $name, so it always displays the login link...
>
> Am I missing something, or is there a limitation in php sessions with
> regards to frames...
>[/color]
PHP doesn't even know about your frames.
It receives a cookie (or get: script.pgp?PHPSESSIONID=56324562134) and
retrieves the session based on that value.
SO If you are using cookies, you should be fine.
If you use URL-rewritting, be sure that you send the right SESSIONID in each
request.
Also be sure to read through php.ini: find the SESSION-section and see if
PHP is allowed to do the rewriting for you.
Another problem can be that the pages you display in the frames are from
different domains. Then NO cookie can be shared (luckily).
Regards,
Erwin Moller
PS: To hunt down bugs like this one, be sure you just check the browsers
cookies, delete them, see what PHP sets, etc. etc.
[color=blue]
> Thanks,
> Ben[/color] | | | | re: PHP Sessions in frames....
On Wed, 02 Feb 2005 12:25:09 +0100, Erwin Moller wrote:
[color=blue]
>
> PHP doesn't even know about your frames.
> It receives a cookie (or get: script.pgp?PHPSESSIONID=56324562134) and
> retrieves the session based on that value.
>[/color]
Am using cookies....[color=blue]
>
> Another problem can be that the pages you display in the frames are from
> different domains. Then NO cookie can be shared (luckily).
>[/color]
Same domain
[color=blue]
> PS: To hunt down bugs like this one, be sure you just check the browsers
> cookies, delete them, see what PHP sets, etc. etc.[/color]
PHP sets the cookies alright... Has PHPSESSID and a hash.
After some more investigation, my sessions don't work at all regardles of
the frames... I just recently upgraded to PHP 4.3.10 from 4.1 though...
Setup is:
Standard form, with a name textfield defined. POSTs to a php script which
starts with
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
$name = $_REQUEST['name'];
$_SESSION['name'] = $name;
?>
.....
<p>You are now logged in, <strong><? echo $name; ?></strong>! Use
one of the links on the left. </p>
<p><a href="test3.php">Test!</a></p>
echo $name displays it fine.
Clicking the test3.php link goes to
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
$_SESSION['name'] = $name;
?>
.....
<? echo $name; ?>
Yet, echo $name doesn't show anything....
Any ideas?
Thanks,
Ben
--
BWGames
to email change de.news to de-news | | | | re: PHP Sessions in frames....
BWGames wrote:
[color=blue]
> On Wed, 02 Feb 2005 12:25:09 +0100, Erwin Moller wrote:
>
>[color=green]
>>
>> PHP doesn't even know about your frames.
>> It receives a cookie (or get: script.pgp?PHPSESSIONID=56324562134) and
>> retrieves the session based on that value.
>>[/color]
> Am using cookies....[color=green]
>>
>> Another problem can be that the pages you display in the frames are from
>> different domains. Then NO cookie can be shared (luckily).
>>[/color]
> Same domain
>[color=green]
>> PS: To hunt down bugs like this one, be sure you just check the browsers
>> cookies, delete them, see what PHP sets, etc. etc.[/color]
>
> PHP sets the cookies alright... Has PHPSESSID and a hash.
>
> After some more investigation, my sessions don't work at all regardles of
> the frames... I just recently upgraded to PHP 4.3.10 from 4.1 though...
>
> Setup is:
>
> Standard form, with a name textfield defined. POSTs to a php script which
> starts with
> <?php
> // start the session
> session_start();
> header("Cache-control: private"); //IE 6 Fix
> $name = $_REQUEST['name'];[/color]
I would strongly suggest you do not use $_REQUEST.
It scans $_GET, $_POST $_COOKIE for the requested name.
You have too little control where your info comes from.
Just use $_GET["somename"] or $_POST["somename"].
[color=blue]
> $_SESSION['name'] = $name;
> ?>
> ....
> <p>You are now logged in, <strong><? echo $name; ?></strong>! Use
> one of the links on the left. </p>
> <p><a href="test3.php">Test!</a></p>
>
> echo $name displays it fine.
>
> Clicking the test3.php link goes to
>
> <?php
> // start the session
> session_start();
> header("Cache-control: private"); //IE 6 Fix
> $_SESSION['name'] = $name;[/color]
This is wrong.
This script doesn't KNOW $name.
SO you assign nothing to $_SESSION["name"]
You better put your errormessages ALL on (Also notices).
Then PHP would complain that $name is unknown...
You probably ment:
$name = $_SESSION['name'];
[color=blue]
> ?>
> ....
> <? echo $name; ?>
>
> Yet, echo $name doesn't show anything....
>
> Any ideas?
>
> Thanks,
> Ben
>[/color]
Regards,
Erwin Moller | | | | re: PHP Sessions in frames....
Erwin Moller <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in message news:<4200b895$0$28977$e4fe514c@news.xs4all.nl>...[color=blue]
>
> Another problem can be that the pages you display in the frames are from
> different domains. Then NO cookie can be shared (luckily).
>[/color]
Thats my problem.
With firefox it is working fine, but I.E is starting a new session on
every page of the content frame. So nothing can be stored at all.
So I am a little bit clueless what to do.
Erwin are you still here? | | | | re: PHP Sessions in frames....
BWGames wrote:[color=blue]
>
> Setup is:
>
> Standard form, with a name textfield defined. POSTs to a php
> script which starts with
> <?php
> // start the session
> session_start();
> header("Cache-control: private"); //IE 6 Fix
> $name = $_REQUEST['name'];
> $_SESSION['name'] = $name;
> ?>
> ....
> <p>You are now logged in, <strong><? echo $name; ?></strong>! Use
> one of the links on the left. </p>
> <p><a href="test3.php">Test!</a></p>
>
> echo $name displays it fine.
>
> Clicking the test3.php link goes to
>
> <?php
> // start the session
> session_start();
> header("Cache-control: private"); //IE 6 Fix
> $_SESSION['name'] = $name;
> ?>
> ....
> <? echo $name; ?>
>
> Yet, echo $name doesn't show anything....[/color]
Of course it doesn't. You overwrite $_SESSION['name'] with
a yet-undefined $name. Replace this:
$_SESSION['name'] = $name;
with this:
$name = $_SESSION['name'];
Cheers,
NC | | | | re: PHP Sessions in frames....
stefan wrote:
[color=blue]
> Erwin Moller
> <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in
> message news:<4200b895$0$28977$e4fe514c@news.xs4all.nl>...[color=green]
>>
>> Another problem can be that the pages you display in the frames are from
>> different domains. Then NO cookie can be shared (luckily).
>>[/color]
> Thats my problem.
>
> With firefox it is working fine, but I.E is starting a new session on
> every page of the content frame. So nothing can be stored at all.
>
> So I am a little bit clueless what to do.
>
> Erwin are you still here?[/color]
Erm, yes, I am now. :P
Bit late maybe.
Been very busy.
If you are still stuck, repost here, ok?
Regards,
Erwin Moller |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,272 network members.
|