iframe formating

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
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

iframe formating

Post by Vegan »

On my chess site I use an old style of document assembly so I was thinking it was time to modernize. php include inherits the underlying format

so I can use <iframe> to replace PHP include, but I was wondering how I can bring in results from a different location

I am aware that <iframe> is cross site friendly so its possible to use another site for result HTML files

then I <iframe> them into a wordpress page

I want the iframe 100% wide so I guess style"width:100%'" is the usual solution

any other ideas I need to consider?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: iframe formating

Post by requinix »

IFRAMEs are old; supporting them in a site is one thing but deliberately adding them where they weren't present before is another thing. Besides that, an iframe and PHP's include/require are two very different mechanisms and they are not equivalent to or replaceable with each other.

What page are you talking about with the inclusions? What are you trying to include from where? Is there a problem you're trying to solve or is it really just about modernizing the site?
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: iframe formating

Post by Vegan »

the chess software spits out some HTML, so I was figuring how hard can it be to emulate php include

<div style="font-family: 'Arial Narrow', Arial, sans-serif;font-weight:100;">
<?php include $_SERVER["DOCUMENT_ROOT"] . "/tournaments/html/group1.html"; ?>
</div>
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: iframe formating

Post by requinix »

Okay, so,

include and require are for PHP code and only for PHP code. Only use them if the file has code and you want it to be executed.
readfile is for dumping (and not attempting to execute) the contents of a file.

In your case there is no code, and anything that looks like code should not be executed. You should use readfile instead.

You also need to consider the HTML you'll be outputting. If group1.html was a full HTML document, with the <html> and <body> and such, then it would not be appropriate to simply readfile() it. Fortunately it is not a full document.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: iframe formating

Post by Vegan »

Anything that JavaScript can do for me on the client side?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: iframe formating

Post by requinix »

Not... really? Is there something you need to have?
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: iframe formating

Post by Vegan »

WP is a pain the butt for PHP as you have to use their API which is far too rigid

still trying to figure out how to leverage wordpress for the chess results

the HTML does not have any <head> or <body> so I was wondering if I need a wrapper for an <iframe> to use that?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: iframe formating

Post by Vegan »

this sort of works but I need to figure out how to get the font properly

Code: Select all

<iframe style="width:100%;font-family: 'Arial Narrow', Arial, sans-serif;font-weight:100;" frameborder="0" scrolling="no" onload="this.style.height=this.contentDocument.body.scrollHeight +'px';" src="/tournaments/html/group1.html"></iframe>
thing I need a wrapper with more css?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: iframe formating

Post by requinix »

Vegan wrote:the HTML does not have any <head> or <body> so I was wondering if I need a wrapper for an <iframe> to use that?
You should, yes. That's also where you would deal with the CSS to apply.

Code: Select all

<iframe style="width:100%;" frameborder="0" scrolling="no" onload="this.style.height=this.contentDocument.body.scrollHeight +'px';" src="/wrapper.php?group1"></iframe>

Code: Select all

<?php // wrapper.php

/*
using the query string for a file path is very dangerous!

the ctype_alnum check requires that the path be just letters and numbers and must happen before
you try to do ANYTHING with $path - including the secondary is_file check.
*/ 

$base = $_SERVER["QUERY_STRING"];
$path = $_SERVER["DOCUMENT_ROOT"] . "/tournaments/html/" . $base . ".html";
if ($base == "" || !ctype_alnum($base) || !is_file($path)) {
	header("HTTP/1.1 404 Not Found", true, 404);
	exit;
}

?>
<html><head><title><?=$base?></title></head><body style="font-family:'Arial Narrow',Arial,sans-serif;font-weight:100;">
<?php readfile($path); ?>
</body></html>
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: iframe formating

Post by Vegan »

thanks, this looks like a more sophisticated idea than i could find after 12 hours hunting around with google

I guess then I can use a combo box to select the desired group from a pool of whatever number I end up with, right now it's 5 but that number will grow as I have to carve up the larger groups

I was thinking if using one page for each group so i can use the WP post listings
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: iframe formating

Post by Vegan »

way my old site works, i had a bullet list of groups, that linked to separate group1...groupn for each group

so it looks like the wrapper for an iframe is kinda like like i am doing now but with a bunch of php instead of one catch all

--------------------

so I put the wrapper under tournaments so html is one more level down, that way the file is all by itself and easy to find if i want to change the font or whatever

so I can now make a post with results, and I can use static pages for each group which can be selected from the results post
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: iframe formating

Post by Vegan »

I just realized a program that can calculate ratings for chess programs can use this as well, but with a <pre> style to use fixed form letters
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: iframe formating

Post by Vegan »

the chess output was still messy, so PHP to the rescue

Code: Select all

<?php header('Content-Type: text/html; charset=ISO-8859-1');?>
the wrapper creates a full HTML document, so I can leverage the <iframe> and change the character set etc etc etc

I added that below the code to load the results:

Code: Select all

<?php // wrapper.php

/*
using the query string for a file path is very dangerous!

the ctype_alnum check requires that the path be just letters and numbers and must happen before
you try to do ANYTHING with $path - including the secondary is_file check.
*/ 

$base = $_SERVER["QUERY_STRING"];
$path = $_SERVER["DOCUMENT_ROOT"] . "/tournaments/html/" . $base . ".html";
if ($base == "" || !ctype_alnum($base) || !is_file($path)) {
        header("HTTP/1.1 404 Not Found", true, 404);
        exit;
}
header('Content-Type: text/html; charset=ISO-8859-1');
?>
<html><head><title><?=$base?></title></head><body style="font-family:'Arial Narrow',Arial,sans-serif;font-weight:100;">
<?php readfile($path); ?>
</body></html>
 
see the results and this is what I was intending, and now I have a perfect clone of the old PHP include

https://computer-chess.azurewebsites.ne ... 1-results/
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply