Help - Search - Members - Calendar
Full Version: PHP and HTML frames
Suggest A Fix PC Support Forums > Internet > Server-Side Coding
Pman
Hi there:

I am having problems accessing global variables from a frames page in PHP.
I have a PHP page (call it page1.php) that sets 2 cookies, this page has no frames btw. In this page I have a link to page2.php which has 2 frames top.php and bottom.php. but in top.php and bottom.php I cant seem to be able to access the cookies that were set in page1.php. I am also NOT able to access any of the variables in $_GET from the TOP.php or BOTTOM.php pages. does anyone know why? or better yet how I can get around it? thanx!

Angoid
Hi Pman,

Firstly, I'd recommend against the use of frames if possible, as they are not "search-engine friendly".

Search engines such as Google don't really recognise them, and as a result a framed site won't be indexed properly.

Also, if there are some out there using older browsers, a framed site may not render correctly.

You'd do better to have a top and bottom include file - yes, it will scroll on and off the page as the user scrolls, but at the end of the day it will be better. Just include your "top.php" and "bottom.php" files. The other advantage of this is that you can do standard stuff in your "top" file - such as connecting to the database, setting a session cookie (see below), outputting standard heading text, and other standard stuff in your "bottom" file such as disconnecting from the database and outputting standard footer text.

Anyway, to answer the question, you'll need to consider the following:

1. Do you start a session at the start of each page? You can do this by calling session_start(), but it must be done before anything else on the page. This sets up a server-side session cookie that lets you share information (variables) between pages.
However, because I'm not really a frames fan, I'm not sure how this would interract with the frames.

2. $_GET[] and $_POST[] are usable without session cookies - use $_GET[] to pick up values sent across on the querystring and $_POST[] to pick up values passed from forms using the POST method.
If you're trying to set up a variable in top.php then access it in bottom.php, AND both files are being loaded by the same frameset file, then it won't work using $_GET[] as there is nothing in the querystring.

I'd pass variables using the session rather than cookies, because it's posible that your users may have disabled them, in which case you'd be up the creek without a paddle.

The other thing you'd need to clarify is if you are loading top.php and bottom.php in the same frameset file, can you guarantee which order the pages will be loaded? If not, then you have no way of knowing whether the variables set up in top.php will even exist when bottom.php is loaded.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.