iFrame alternative - php includes?

I’m constructing a page that will contain links that then load content into a single positional area on that page.

I could use an iframe set-up, and this does indeed work, however, is there a simple alternative method that I can use that employs php?

I get the idea behind ‘php includes’, but am stuck as to how to get the links to load the required content into a designated layer. Any help will be highly appreciated.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

PHP includes run (on the server) when the page is requested. A single
php file may include as many other files (php or not) as it requests.

A little sidebar: Each included file is added to the page source as
raw text; in the case of PHP files, this happens before the composite
script is evaluated for code, so what is added will be evaluated in
one pass along with the base code in the page. If you want the
result of the included page to be added (you want it to be
rendered as code, then added as final HTML to your output stream) then
you need to create a function to do that.

Anyway, iframes have one useful feature that PHP includes do not: they
can handle a complete page being added to another complete page
without generating an invalid mess. But if you were to use a PHP
include as a straight drop-in replacement for an iframe, you would end
up with a page-within-a-page, or the aforementioned mess.

If you want to include a page in another page using PHP, you either
have to strip off its HTML, HEAD and BODY tags, and include only the
content of the BODY tag (there’s an Action for that, called PHP Make
Insert Page) or you have to live with the fact that your composite
page will be really broken and probably won’t display at all in some
browsers.

Long story short: Change your page filename to end in .php rather
than .html. Page / Insert / Markup Item. In the resulting dialog box,
add <?php include_once('path/to/include/file.php'); ?> or (big IF
here) if your server has enabled protocol handlers for files: <?php include_once('http://url.of.your.site/page.html'); ?> Okay the
dialog, then look on your page for a 100px square box with a [H] in
the corner. Resize and position this box to your liking. The remote
file will appear there when the page is loaded through a real Web
server (not locally using any form of preview). But again, you really
must make sure that what you are loading is a fragment of a page, not
an entire stand-alone page. For that, you really should stick to the
iframe.

Walter

On Feb 24, 2009, at 9:05 AM, Ian Halstead wrote:

I’m constructing a page that will contain links that then load
content into a single positional area on that page.

I could use an iframe set-up, and this does indeed work, however, is
there a simple alternative method that I can use that employs php?

I get the idea behind ‘php includes’, but am stuck as to how to get
the links to load the required content into a designated layer. Any
help will be highly appreciated.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walter - I’ve now learned about using only the body content of a page for includes, and that there’s an action to strip the stuff I don’t want. Excellent and useful. Very useful. I’ve suddenly seen ways of standardising menus, footers etc without using Master Pages, but still using the box model.

So… how do I now get the ‘php includes’ content of a div on a page to change, depending on a series of links clicked on that very same page? I can insert the ‘php include’ markup in the div, but it’s getting it to change that’s got me. It must be a string that passed as part of the link I guess.

Green but very eager would best describe my position with php!


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

CODE WARNING

You’ve answered your own question. You can do this any number of ways,
but the simplest would be using a “querystring” variable to pass along
the desired target:

http://example.org/includepage.php?target=foobar

NB that I am not including the entire path to the target file – that
would be a serious security flaw that any idiot could exploit.

In your includepage.php, you would set up (and cleanse) the input from
the querystring in the Before HTML section of the Page / HTML Markup
dialog thusly:

<?php
$base = dirname(__FILE__);
if(isset($_GET['target'])){
	$link = preg_replace('~[^a-z]~','',$_GET['target']);
	$link = $base . '/' . $link . '.html';
	if(!file_exists($link)) $link = $base . '/default_content.html';
}else{
	$link = $base . '/default_content.html';
}
?>
~~~

Then in your Markup Item further on down the page, you would simply  
add `<?php include_once($link); ?>`

What that lump of code does is first "root" itself in the current  
directory. This keeps someone from getting you to escape the current  
directory (perhaps looking for /etc/passwd or its friends). Next, it  
looks to see if there is a 'target' querystring attribute. If there  
is, then the target is stripped of anything that isn't a-z lower-case,  
and then mashed with the current directory path and .html to get the  
final path to the file. Finally, the link is tested before going any  
further, and set to a reasonable default if it doesn't work. And  
again, if there isn't a target attribute on the current link, the path  
is set to your default.

Hope this helps, and post further questions about code in the Dynamo  
list, where it tends not to scare the natives as much!

Walter
On Feb 24, 2009, at 9:47 AM, Ian Halstead wrote:

> So... how do I now get the 'php includes' content of a div on a page  
> to change, depending on a series of links clicked on that very same  
> page? I can insert the 'php include' markup in the div, but it's  
> getting it to change that's got me. It must be a string that passed  
> as part of the link I guess.


_______________________________________________
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walter - this is plenty to keep me going for now. I was wondering about posting this in the Dynamo list, but it’s good to be a little scared every now and again! It’s only though the odd mention of php on this list that I’ve gradually become curious, and I’m very easily scared. Less so now though.

Thanks again.

Ian


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options