$_SESSION and frames

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skooter
Forum Newbie
Posts: 20
Joined: Sun Jul 01, 2007 5:29 am

$_SESSION and frames

Post by skooter »

Do frames affect the $_SESSION variable??

I've got two iframes in a shopping window, each file has session_start() called, frame one puts the values into $_SESSION and frame two prints it. Only it doesn't. I've popped a loop in to check if its working and it is, but nothing comes up

is this right: echo $_SESSION[$i] . "\n"; (or print) in a loop
and: <form name="carter" action="phpShoppingCartWindow.php?lister('name')" method="post">

where listener is a function to put the value into the $_SESSION array

Any thoughts???
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

javscript iframe and php

Post by yacahuma »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


From your example I dont know why you might want to do that.  If you have an iframe it make sense to update the iframe through javascript otherwise just submit the form.  If you still want to use a session, just make sure the session is define before you use it in the other page. There are no restrictions or problems with that. Take a look at how you will do it with javascript.

FILE: iframe.php

Code: Select all

<?php
if (isset($_GET['itemID'])) //DO ANY DB STUFF HERE
  echo $_GET['itemID'];
?>
FILE: itest.php

Code: Select all

<html>
<head>
<title>Page title</title>
</head>
<script>
function toggleread(exby)
{
 var ischecked = exby.checked? 'Y':'N';
 var itemID = exby.value;
 inboxIFrame.location.href = 'iframe.php?itemID=' + itemID + '&ischecked=' + ischecked;
}
</script>
<body>
<form name="">
<input type="checkbox" name="chk[]" onclick="toggleread(this)" value="345" />
<input type="checkbox" name="chk[]" onclick="toggleread(this)" value="355" />
<input type="checkbox" name="chk[]" onclick="toggleread(this)" value="377" />
<input type="checkbox" name="chk[]" onclick="toggleread(this)" value="388" />
</form>
<iframe name="inboxIFrame" src="iframe.php" style="width:500px; height:100px; border: 1px;"></iframe>
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by yacahuma on Sun Jul 01, 2007 9:59 am, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I believe frames are given their own "window" and are counted as separate windows. If they are the same site, they will still share the same session id.
skooter
Forum Newbie
Posts: 20
Joined: Sun Jul 01, 2007 5:29 am

Post by skooter »

Thanks for the replies!

They're all in the same site, and sharing session ID (would I be right in assuming thats the first two variables in the $_SESSION array??), so I assume they'd be sharing the session array as well. So I figured I'd pop the info into session and from there print it out in the cart window (the website I'm writing takes maybe one email order a week, usually less than 10 items and doesn't need to be secure - no credit cards, online payment etc...).

Simple I know, so am I allowed to do that?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Each frame is a separate page request. Each will only need to handle sessions in the normal fashion.
skooter
Forum Newbie
Posts: 20
Joined: Sun Jul 01, 2007 5:29 am

Post by skooter »

So whats the trick?

they each need session_start() called? or just once?? then they each have access to the $_SESSION variable (correct??), yet cant seem to print out from it...

Do I have to refresh the cart-frame each time the function is called??
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Every page using sessions will require session start.
Post Reply