Page 1 of 1

Importing Pages To Php Sometimes i need to import to my theme Rate Topic: ***** 1 Votes

#1 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Posted 21 December 2004 - 03:46 PM

Due to several reasons like, different database, or function calls not working when included into your dynamic site, other reasons. but to make it easy for me to load php add-ins to my dynamic theme i made a function.
sometimes need a cgi/perl page to import.
can setup ifelse as i did to look for pages of any type.

I am also able to specify the size, and no border.
for a few security reasons i have used full server url to see if the file exists, if it does, load into an iframe. and add a link to open in a new window if the browser does not suppor it.

config settings,
<?php
$iframe_height="600";
$iframe_width="550";
//full server root path
$iframe_contents_dir="/home/path/to/dir";
// http url to same dir as $iframe_contents_dir
$iframe_contents_url="http://localhost";
$iframe_style="style=\"width:$iframe_width; height:$iframe_height;\"";
?>


now we need to build the function,
this funtion does several things like if the page is not found, nothing happens, the else statement.
on my site, $main_page is the action, change to yours.
so to call a page pagename.php?main_page=import-page-name, no .php is a securty thing also, so that only the file extentions you say can be loaded.
to see settings for debugging un-comment print after else
<?php
function iframe_content($main_page) {
	global $main_page, $iframe_contents_url, $iframe_contents_dir, $iframe_style, $iframe_contentfile, $mypage;
	$iframe_contentfile = "$iframe_contents_dir/" .$main_page. ".php";
	if (is_file($iframe_contentfile)) {
$mypage = "$iframe_contents_url/" .$main_page. ".php";
print " <a href=\"$mypage\" target=\"_new\">Open in new Window</a><BR><iframe frameborder=\'0\' $iframe_style src=\"$mypage\"> </iframe>";
	} else {
//print "Page not found <BR> $iframe_contents_dir <BR>$iframe_contents_url";
}
}
?>


now we need a way to call the function, placed were you want the content to be displayed.
<?php
iframe_content($main_page);
?>


completed code,
<?php
$iframe_height="600";
$iframe_width="550";
//full server root path
$iframe_contents_dir="/home/path/to/dir";
// http url to same dir as $iframe_contents_dir
$iframe_contents_url="http://localhost";
$iframe_style="style=\"width:$iframe_width; height:$iframe_height;\"";


function iframe_content($main_page) {
	global $main_page, $iframe_contents_url, $iframe_contents_dir, $iframe_style, $iframe_contentfile, $mypage;
	$iframe_contentfile = "$iframe_contents_dir/" .$main_page. ".php";
	if (is_file($iframe_contentfile)) {
$mypage = "$iframe_contents_url/" .$main_page. ".php";
print " <a href=\"$mypage\" target=\"_new\">Open in new Window</a><BR><iframe frameborder=\'0\' $iframe_style src=\"$mypage\"> </iframe>";
	} else {
//print "Page not found<BR> $iframe_contents_dir <BR>$iframe_contents_url";
}
}
iframe_content($main_page);

?>


Have fun
Dave

This post has been edited by SpaceMan: 26 December 2004 - 09:57 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Importing Pages To Php

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,890
  • Joined: 10-May 07

Posted 09 November 2007 - 03:02 PM

This is a great way to add menus. Reusable code rocks.
Was This Post Helpful? 0
  • +
  • -

#3 paste120  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-November 07

Posted 06 December 2007 - 05:00 PM

Great tutorial.
Nice catch on the import page security, Cant tell you how many times ive seen it done wrong.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1