Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,156 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,088 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Importing Pages To Php

 
Reply to this topicStart new topic

> Importing Pages To Php, Sometimes i need to import to my theme

Rating  5
SpaceMan
Group Icon



post 21 Dec, 2004 - 03:46 PM
Post #1


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,
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;\"";
?>


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
CODE

<?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.
CODE

<?php
iframe_content($main_page);
?>


completed code,
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 Dec, 2004 - 09:57 PM
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

no2pencil
Group Icon



post 9 Nov, 2007 - 03:02 PM
Post #2
This is a great way to add menus. Reusable code rocks.
Go to the top of the page
+Quote Post

paste120
*



post 6 Dec, 2007 - 05:00 PM
Post #3
Great tutorial.
Nice catch on the import page security, Cant tell you how many times ive seen it done wrong.
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 9/5/08 05:15PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month