Nov 8, 2009
Pages: 1, 2

Tutorial: PHP Includes

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

Tutorial: PHP Includes

PHP_Newb
Also- if you do not put the <?php ?> tags in, the browser will count it as HTML. so if you put this in an include file: $test1 = test2 echo ("$test1")
the browser will count it as HTML. But if you put in the PHP tags it will display the echo script

Comment/Reply (w/o sign-up)

Brian
You're right. I would much rather use PHP or some other include method, but I couldn't get those to work. and as for JavaScript not being enabled, my pages will still work even with out the includes. The pages just won't look quite as good, but will still be completely functional. But you are right: I wouldn't recommend JS includes either.

Comment/Reply (w/o sign-up)

Dread
Cool il use that when i got those 50 posts or ten lol =)

Comment/Reply (w/o sign-up)

prodigy
Yes includes are a good method of optimising a template. I enjoy using includes into certain CMS's and other various template driven scripts. All that needs to be done is to include the html page (or other) below the split code of your main html (or other) page. Eg have a header and a footer, with content inbetween (which is driven by the script). If you do this i suggest you install these scripts into seperate folders with your header aand footer html (or other) pages. Sort of hard to explain as it varies with certain scripts, but it is simple to implement.

Heres what I meant:

With my order system i did a little bit of templating: http://www.shothost.com/order

With my links directory I did the same thing:
http://www.shothost.com/links

Normally these scripts have a default boring look, but I have sort of customised it in a way, nothing to flash but it works for me.

Maybe you guys could experiment smile.gif

 

 

 


Comment/Reply (w/o sign-up)

tlc
I have a question.. I had truble to put include text file without that it would but "1" in the end of the text? Where It came from? Finally I got rid of it, but still I don't understand why.....

Comment/Reply (w/o sign-up)

finaldesign
I recently had some problem with includes. So here it is, if you know solution lemme know...
Problem:
If you have one php file in your public_html/ folder, called index.php, and in that index.php you include another file which is in public_html/directory/file.php - and in that included file "file.php" there is another inclusion of public_html/directory2/file2.php how can you manage to work it out... ?

It gets me lots of errors, and I end with solution that it can't be done, because if I include something in some file in root directory (e.q. index.php) script will stay executed in that directory (hipoteticly) and if I include file which has line of code in it self
include("../directory2/file2.php");
what it really does it goes directory back beyond public_html and finds nothing... - complicated huh sad.gif ? and I cannot change the code of that file.php because Im using it in another file and that file is in folder public_html/directory/ so that file needs that ".." part of code in include...
How to solve this complication? any suggestion for different programming...?

Comment/Reply (w/o sign-up)

chiiyo
Hmm... maybe use absolute URLs? Instead of using relative urls like "../directory/index.html" you could use "http://whatever.astahost.com/directory.index.html" in your embedded file (in this case, file.php) so that you won't have to worry about the script staying in the first file and not budging.

Not a very elegant solution, but it might work if you only have a few files with this problem.

Comment/Reply (w/o sign-up)

Coach
QUOTE (chiiyo @ Apr 15 2005, 12:57 PM)
Hmm... maybe use absolute URLs? Instead of using relative urls like "../directory/index.html" you could use "http://whatever.astahost.com/directory.index.html" in your embedded file (in this case, file.php) so that you won't have to worry about the script staying in the first file and not budging.
Not a very elegant solution, but it might work if you only have a few files with this problem.
*

Ii works in something like:
QUOTE (Adapted from others websites)
<html>
  <head>
      <title>Include Sample</title>
  </head>
  <body>
    <?php
            include("header.php");
      ?>
      <table width="95%" cellspacing="15" cellpadding="5" border="0">
        <tr>
            <td valign="top" width="120">
              <?php
              include("menu.php")
              ?>
            </td>
            <td valign="top">
  <?php
switch ($_GET['c']) {
    case '1':
    include("content" . $_GET['c'] . ".php");
        break;
    case '2':
    include("../www/file2/content" . $_GET['c'] . ".php");
        break;
    case '3':
        include("../www/file3/content" . $_GET['c'] . ".php");
        break;
    default:
        include('content1.php');
  break;
}
?>
            </td></tr></table>

      <?php
            include("footer.php");
      ?>
  </body>
</html>


The $_GET['c'] comes from:
QUOTE
<p align="center" style="font:bold 1em sans-serif;color:#000099">
  <a href="index.php?c=1">Home</a><br>
  <a href="index.php?c=2">Reality</a><br>
  <a href="index.php?c=3">Mision</a><br>
</p>

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2
Similar Topics

Keywords : Php Includes

  1. CMS101 - Content Management System Design - Basic CMS With PHP Includes (15)
    Overview: Frequently people ask about Content Management Systems here and are looking for
    advice regarding which CMS would work best for them. Often, the user requesting the help
    doesn't realize that they can design their own CMS that will provide them with the results they
    are looking for without needing to install a bulky program. This usually stems from the relatively
    few features that users want from their CMS. Many users just want an easy way to manage their
    website and edit their content. In this tutorial we'll discuss a very simple way to cr...
  2. Creating And Using Includes With PHP - A simple tutorial (6)



Looking for php, includes

See Also,

*SIMILAR VIDEOS*
Searching Video's for php, includes
advertisement



Tutorial: PHP Includes

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com