UK WEB HOSTING FORUM FOR DISCUSSION ON WEB HOSTING SERVICE AND SUPPORT
LINUX HOSTING WINDOWS HOSTING PACKAGES SHOPPING CART OSCOMMERCE ZEN CART AGORA
ECOMMERCE HOSTING ASP MSSQL FRONTPAGE HOSTING PHP MYSQL HOSTING DISCUSSION FORUM
CPANEL RESELLER HOSTING DEDICATED SERVER VPS HOSTING PLESK VIRTUOZZO
Quick Search
Your forum announcement here!

  UK Web Hosting | Dedicated Server Windows and Linux VPS Forum > Technical Support > Tutorials / How to?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 22-01-2008, 23:50
Junior Member
 
Join Date: Jan 2008
Location: Australia
Posts: 14
Send a message via MSN to shaine Send a message via Yahoo to shaine
Lightbulb PHP Includes

» Step One
If you use php includes, you can easily change things on your site. And its more neatier and easy to install. Keep reading! First, you will need a text editor(eg. notepad, dreamweaver or frontpage) and a html knowledge.

All of your files must be saved as .php extension. Or else it won't work. Now, you must create two files. We gonna call the first file, MAIN and the second file INCLUDE. Put this code below anywhere into your MAIN file(eg.index.php / your index page):

Code:
<?php include("include.php"); ?>
------------------------------------------------------------------------------------

» Step Two
Now, where into the INCLUDE.php file. On this file, you can put things what you like(eg. links, affiliate section, update section etc.).
Then after that, you need to upload the files.

If you're going to add / edit something you don't need to edit the index file, only the include.php file. All the codes you put into the include.php will show up into your index page / whatever you call it.

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

Please reply to this thread if you need help.

*also please let me know if this thread is not allowed to be post.

~ Posted on 23/01/2008
__________________
F.erocio.us
Please let me know if I did something wrong. I'm only new.
I post 5-10 a day. I don't post more than that.


~ Shaine
from Australia

Last edited by shaine; 22-01-2008 at 23:58.
Reply With Quote
  #2 (permalink)  
Old 23-01-2008, 03:11
System Administrator
 
Join Date: Dec 2006
Posts: 612
Default

Very nice tutorial for PHP newbies They'd be thankful to you for sure Keep up the Good Work !
__________________

Rock _a.k.a._ Jack L.

http://www.eUKhost.com
Windows Hosting || Windows Reseller Hosting
Reply With Quote
  #3 (permalink)  
Old 24-01-2008, 16:36
mephisto's Avatar
Senior Member
 
Join Date: Feb 2007
Location: Darlington
Posts: 101
Send a message via ICQ to mephisto Send a message via MSN to mephisto
Default

include has another feature, you can assign the return value of the script to a variable. So if you wanted to build up a webpage you can do this with includes.

PHP Code:
<?php
    
/**
     * file: header.php
     */
    
    
$external = include('external.php');    
    return 
"<html><head><title>$title</title>$external</head><body>\n";
?>

<?php
    
/**
     * file: external.php
     */
    
$output '';
    if(
$scripts && is_array($scripts)) {
        foreach(
$scripts as $script) {
            
$output .= "<script type=\"text/javascript\" src=\"$script\"></script>\n";
        }
    }
    if(
$styles && is_array($styles)) {
        
$output .= "<style type=\"text/css\">";
        foreach(
$styles as $style) {
            
$output .= "@include $style;\n";
        }
    }
    return 
$output;
?>

<?php
    
/**
     * file: footer.php
     */
    
return "<div id=\"footer\">goodbye world</div></body></html>";
?>

<?php
    
/**
     * file: index.php
     */
    
    
$scripts = array(
        
'script1.js',
        
'script2.js'
    
);
    
    
$styles = array(
        
'style1.css',
        
'style2.css'
    
);
    
    
$title "include example";
    
    
$page = include('header.php');
    
$page .= 'hello world';
    
$page .= include('footer.php');
    
    echo 
$page;
?>
This example allows the title, javascript files and stylesheets to be assigned to variables before the includes and then they are all put into a single string before printing them to browser.

There is also a function require, which generally performs better because the require function only looks at the code once it is used, whereas include looks at the code straight away. The other difference between the 2 is that require will raise a fatal error if the file is missing, whereas include will only raise a warning.

Both include and require have similar functions, include_once and require_once. They their names suggest, they will only be referenced once in the code, the best use is when you have modular code which has multiple dependencies, because then php won't try to redeclare your functions or classes.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 23:33.

 

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by Web Hosting 3.1.0
Copyright © 2001-2008, eUKhost.com. All rights reserved.

 
Site Map

VPS Hosting
VPS Hosting plans

Dedicated Server Hosting
Dedicated Server plans

Business Web Hosting
100% uptime Hosting

Cpanel Hosting
cPanel Shared Hosting

Reseller Hosting
Reseller Web Hosting

Windows Hosting
Windows Shared Hosting

Windows VPS

Windows VPS Hosting

Semi Dedicated Servers
Semi-Dedicated Hosting

Dedicated Server Mirroring
Dedicated Server Mirroring

Webhosting Knowledgebase
Frequently asked Questions

Web Hosting Blog
eUKhost Blog

Web Hosting Support
Support Helpdesk

UK Data Center
eUKhost Datacenter

Web Hosting Forum
eUKhost Forum

Support Tutorials
Online Flash Tutorials

Offsite Back-up Plans
Remote Backup Service

Customer Testimonials
eUK Customer Testimonials


knowledgebase articles

eUKhost.com Services

Pre-Sales Questions
Pre-sales FAQ's

Domain Names
Domain registration FAQ's

cPanel Hosting
cPanel Hosting FAQ's

Windows Web Hosting
Plesk Control Panel

Reseller Hosting
Reseller Hosting FAQ's

VPS Hosting
Virtual Private Server

Semi-Dedicated Servers
Semi-Dedicated FAQ's

Dedicated Servers
Dedicated Server Hosting


popular blog categories


Web Hosting
Website Hosting articles

UK Web Hosting
UK Hosting articles

Dedicated Server Hosting
Dedicated Server guidelines

VPS Hosting
VPS hosting articles

cPanel Hosting
cPanel Hosting articles

Linux Operating System
Linux Operating techniques

Windows Web Hosting
Windows plesk articles