Hi all, I am new to PHP and have come from an ASP background and took the plunge into PHP and thus far its far better, however I have some issues with a script I am writing and would appreciate some help.
I am trying to load a page into an <iframe> and attempting to stop the “framecontent.php” page from loading on its own i.e. not in the frame unless the var $textonly is found then I will load a text only menu.
I do not want to use Javascript, as the text only version will be run without JS or CSS.
When I run the code it works to a point, when I open up the framed paged in a new window it does not re-direct, as it should, although I have had it doing so at the cost of some other code area not working.
I have got myself into a bit of a mess here and had it working but at different levels from the “framecontent.php” looping a redirect, the ”framecontent.php” page running without the frame when it shouldn’t and all sorts of issues.
I do not want to send a query string to the framecontent.php other than $textonly as and when needed as the “framecontent.php” would be able to be loaded other wise when it shouldn’t.
It would be easier for you guys to save these pages to your local PHP server if you have one to see how this breaks.
I know my code is not as logical as it should be, been trying this for a few days now =/
Thanks in advance for your help.
I am having trouble with the following code.
FRAMED PAGE (frameset.php)
<?php
session_start();
$_SESSION['frames'] = 1;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<p><a href="framecontent.php" target="frame">framecontent.php load in iframe</a> <a href="framecontent.php" target="_blank">framecontent.php load in new window</a></p>
<iframe name="frame" src="framecontent.php" align="middle" width="700"height="500"></iframe>
</body>
</html>
CONTENT PAGE (framecontent.php)
<?php
$siteurl = "frametest.php"; // Edit to any URL
session_start();
// if session frames is NOT found and $textonly has NOT been passed
// redirect to home page $siteurl
if (!isset($_SESSION['frames']) && !isset($_GET['textonly'])) {
header( 'Location: ' . $siteurl );
}
?>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
// if session frames is NOT found and $textonly HAS been passed
// load text only menu
if (!isset($_SESSION['frames']) && isset($_GET['textonly'])) {
$query = $_GET['textonly'];
echo 'Load text based navigation';
}
// if session frames is found and $textonly HAS been passed
// load text only menu and destroy session frames
if (isset($_SESSION['frames']) && isset($_GET['textonly'])) {
$query = $_GET['textonly'];
echo 'Load text based navigation';
unset($_SESSION['frames']);
session_destroy();
}
// if session frames is found and $textonly has NOT been passed
// keep the session alive and show page content
if (isset($_SESSION['frames']) && !isset($_GET['textonly'])) {
echo 'Stay in frames';
}
// convert to else if
// unset($_SESSION['frames']);
// session_destroy();
?>
</body>
</html>
Posted @ http://www.phpbuilder.com/ 08/04/2007