Page 1 of 1
$_SESSION and frames
Posted: Sun Jul 01, 2007 6:21 am
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???
javscript iframe and php
Posted: Sun Jul 01, 2007 7:20 am
by yacahuma
feyd | Please use 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
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]
Posted: Sun Jul 01, 2007 8:05 am
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.
Posted: Sun Jul 01, 2007 10:05 pm
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?
Posted: Sun Jul 01, 2007 10:21 pm
by Benjamin
Each frame is a separate page request. Each will only need to handle sessions in the normal fashion.
Posted: Mon Jul 02, 2007 12:57 am
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??
Posted: Mon Jul 02, 2007 1:01 am
by Benjamin
Every page using sessions will require session start.