Jul 26, 2008

Php's Include Function (info) - Want info about the include() function?

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming
Pages: 1, 2

free web hosting

Php's Include Function (info) - Want info about the include() function?

thablkpanda
Word,

I know plenty of people out there that just primarily script in php, however know very little about the script that potentially saved my web-site.

For an example, I can't even show you how large my former index page looked like, seeing as it is well over... 250 lines.. but, here's the condensed version on the require() diet.

CODE
<html>
<body>
<? require 'header.php';?>
<? require 'indextable.php';?>
</body>
</html>


It's about 87 bytes.
The old one was 825 kb (kilobytes).

That's Weightwatchers for PHP right there...

Through the magical function called require() I've consolidated the size of my main-pages, and saved ALOT of scripting time.

What it does is make the page 'call upon' another PHP page on the web, to display in the place where the require() tag is located. So you're seeing my whole index page, just in a dummed down version.

The page header.php, consists of the <img src='img.png'> tags that make up my navigational bar, and logos. Seeing as there were roughly ten of them, I looked for a way to clean up the parts you'd see if you viewed my code.

The page indextable.php consists of the tables and contents that make up my text and stuff of my site. There is a 3x2 table on the index page, that has information that will be updated regularly. And through the magic of PHP, I can do it all 5 times faster!

This may be old news for some PHP guru's out there, but require() is the biggest factor in my success!

If you want specifics on how to use the require() function, visit Google - PHP Require() Function

Happy Scripting
Tha Blk Panda

 

 

 


Reply

ill
CODE
<?php include 'links.php'; ?>


This is a way to include pages into other pages. It's sort of like the iframe function in html. It's a lot better to use. It's a way to easily update parts of your site on all pages. Like for instance you can have your menu on one page, then include it into all the pages using the code above, in this case I have shown my include function that shows my links at the bottom of my website.. smile.gif

Reply

Roly
I never used frames for navigation before I started using PHP.

Reply

ket
nice info for someone like me, that has been interesting in learning PHP but don't have the time/don't know where to start. i guess this is a good begining.

im gona have to try this later. thanks for the tip.

Reply

bjrn
Just the difference between require() and include().

If require() fails, it produces a fatal error, stopping the whole parsing process. If include() fails it onlyproduces a warning. So if you want everything to stop when you want to get content from an other file, use require, otherwise use include.

There are also two other variants: require_once() and include_once(), which work as the normal ones, except that if the code has already been included earlier, it won't be included a second time (in the same page).

Reply

Mike
^^^Heh, you're exactly correct.

Another nifty little function that I like about PHP is the mail() function. I'll provide y'all with the code for it..

CODE
<?php

$headers = 'From:[B]youremailaddress@yourisp.com[/B]\r\n";
$headers .= 'Reply-To:[B]youremailaddress@yourisp.com[/B]\r\b";
$headers .= 'Content-Type: text/html;\r\n charset=\"iso-8859-1\"\r\n";

$body = "

[b]What you want to appear in the e-mail would go here..  You can use some HTML tags like b,i,u, and the table tags.[/b]

";

mail("[b]emailaddressofrecipient@peronsisp.com[/b]", "[b]subjectofemail[/b]", $body, $headers);

?>

****EDIT EVERYTHING WITH A '[ b ]' TAG NEXT TO IT (WITHOUT THE SPACES).. TO SEND THE MESSAGE YOU MUST GO TO THE LINK THAT YOU SAVED IT AS.. IF YOU SAVED IT AS 'mail.php' YOU WOULD GO TO http://yoursite.trap17.com/mail.php IF IT IS IN THE 'WWW' FOLDER. THAT MAY NOT BE THE LINK TO YOUR SITE FOR ALL USERS!****

 

 

 


Reply

karlo
require()

If the required file dosen't exists, the whole script halts or stops.

include()

The whole script still runs even if the include file dosen't exists.

Research about require_once() and include_once()

Reply

Mike
Exactly what karlo and everybody has been saying. If you use the require() function and the file that you are trying to get information from does not exist, than the page will become a Fatal Error and the whole thing is screwed up. If you use the include() function and the file that you are trying to include does not exist, the page will still load but with a warning at the top saying something like:

WARNING: (/linkthingtothefileyoutriedtoinclude) File does not exist.

if you use require_once() or include_once(), it will do the same as just include() and require() but if the file you are trying to require or include has already been included or required, the script will stop.

Reply

thablkpanda
QUOTE(Mike @ Feb 5 2005, 02:34 PM)
Exactly what karlo and everybody has been saying.  If you use the require() function and the file that you are trying to get information from does not exist, than the page will become a Fatal Error and the whole thing is screwed up.  If you use the include() function and the file that you are trying to include does not exist, the page will still load but with a warning at the top saying something like:

WARNING: (/linkthingtothefileyoutriedtoinclude) File does not exist.

if you use require_once() or include_once(), it will do the same as just include() and require() but if the file you are trying to require or include has already been included or required, the script will stop.
*



Then it's kinda a given to only use require() files that you know exist, not images, or something that's prone to corruption or the like. (how many times has that been said anyway? I think we get the point... dry.gif )

LOL
Panda Out biggrin.gif

Reply

karlo
QUOTE(thablkpanda @ Feb 3 2005, 09:53 AM)
Word,

I know plenty of people out there that just primarily script in php, however know very little about the script that potentially saved my web-site.

For an example, I can't even show you how large my former index page looked like, seeing as it is well over... 250 lines.. but, here's the condensed version on the require() diet.

CODE
<html>
<body>
<? require 'header.php';?>
<? require 'indextable.php';?>
</body>
</html>


It's about 87 bytes.
The old one was 825 kb (kilobytes).

That's Weightwatchers for PHP right there...

Through the magical function called require() I've consolidated the size of my main-pages, and saved ALOT of scripting time.

What it does is make the page 'call upon' another PHP page on the web, to display in the place where the require() tag is located. So you're seeing my whole index page, just in a dummed down version.

The page header.php, consists of the <img src='img.png'> tags that make up my navigational bar, and logos. Seeing as there were roughly ten of them, I looked for a way to clean up the parts you'd see if you viewed my code.

The page indextable.php consists of the tables and contents that make up my text and stuff of my site. There is a 3x2 table on the index page, that has information that will be updated regularly. And through the magic of PHP, I can do it all 5 times faster!

This may be old news for some PHP guru's out there, but require() is the biggest factor in my success!

If you want specifics on how to use the require() function, visit Google - PHP Require() Function

Happy Scripting
Tha Blk Panda
*



This person is right

QUOTE(bjrn @ Feb 3 2005, 06:46 PM)
Just the difference between require() and include().

If require() fails, it produces a fatal error, stopping the whole parsing process. If include() fails it onlyproduces a warning. So if you want everything to stop when you want to get content from an other file, use require, otherwise use include.

There are also two other variants: require_once() and include_once(), which work as the normal ones, except that if the code has already been included earlier, it won't be included a second time (in the same page).
*


Reply



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*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Similar Topics

Keywords : phps, include, function, info, info, include, function

  1. PHP Function To Add Previous and Next Page Feature
    useful php function (0)
  2. Agent-principal Relationships
    some info on this important subject (0)
    In the relationship between an agent and a principal, both parties consent to the agent having the
    ability to act on behalf of the principal. This is known as a form of principal-agent relationship
    called power of attorney. Such a relationship plays an important role in business, whether it be in
    the workplace, a partnership, or a corporation. There are three types of authority in a
    principal-agent relationship: express, implied, and apparent authority. Express authority is what
    the principal directly tells the agent his duties and responsibilities are. This cannot ....
  3. Plants And Water Loss
    some info on growing plants in dry conditions (0)
    Transpiration is a plant’s loss of water, usually through the stomates of leaves. Plants have guard
    cells to regulate the water loss. These guard cells open and close the stomates in response to
    various environmental conditions; darkness, lack of water within the plant, and extreme temperatures
    cause the guard cells to close the stomates while light, plentiful water, and favorable temperatures
    cause them to open the stomates. Some stomates must be open even in unfavorable conditions so that
    the plant can take in carbon dioxide. Dryland farming is the growing of crops....
  4. Enzymes And Health
    Some interesting info on enzymes (0)
    Enzymes act as catalysts in living organisms which allow important chemical reactions to occur at
    lower temperatures. They are not altered in the process and can be used in many reactions. Most of
    the chemical reactions that occur in living organisms are regulated by enzymes and would happen much
    slower without them. For example, without the digestive enzyme carboxypepdidase, it would take
    seven years to digest a hamburger. Ethyl carbamate is a compound found in fermented beverages that
    can cause cancer in various organisms. Its precursor is urea, an intermediate du....
  5. Rate An Operating System!
    I need this info for my comic strip. (0)
    I have a very irregular comic strip that I make, and I want my next strip to be in the spirit of
    XKCD's comic "f--- grapefruit", and rate operating systems instead. I'm running a poll
    here, based on whether people think an operating system is better than Windows 2000 or not, which
    I'm going to use as a benchmark (sea-level point) for rating systems. The rating system is on 3
    axes, "usefulness", "reliability", and "security". Basically, for the poll, check which ones you
    think are more useful than Windows 2000 on the first poll, which ones are more reliable ....
  6. Reset My Site Pelase
    read for more info (6)
    Can you just reset my cpanel / website FTP and all to how it was when I got it new please? Don't
    change any passwords, just make it so it's like brand new again. thanks --why? because I have
    some files in public_HTML that I am trying to delete even after I give it 777 it says permission
    denied so please reset /smile.gif" style="vertical-align:middle" emoid=":)" border="0"
    alt="smile.gif" />....
  7. Question Regarding Php Function
    It's all about PHP mail (12)
    I found out many people recommend Trap 17 as their free webhost, and I'm interested too! My
    experience with all free host is having PHP Mail function disabled (and need to choose premium/paid
    package to enable it) /sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif"
    /> . Do Trap17 enable php mail function? Because it will be very useful for me as I creating a
    bulletin board (forum). Thank you for answering /biggrin.gif" style="vertical-align:middle"
    emoid=":D" border="0" alt="biggrin.gif" /> .....
  8. Yoga
    info about yoga (1)
    there are millions of yoga techniques were written in the ancient time which were came from asia .
    yoga gives focus of mind and power of the body. one of the best yoga practices - pranayama (breath
    technique) and different poses and technique makes yoga as vast category....
  9. Php Allow Url Include Question!
    Need an admin to clarify something... (10)
    Hi, i've just signed up to your hosting over the last few days, and its been very fustrating
    that you don't allow the directive: allow_url_include. Do you think that there could be anyway
    that you could turn it on? i've installed a login and hit counter script and i had to edit half
    of it. I also want to 'include' my page list on all of my pages, to make it easier to
    update them, but the only way i would be able to do this is upload a page list to every directory,
    which defeates the purpose. And i can't use SSI because i can't use PHP with ....
  10. Get User Info True Sessions Or Cookies
    need help on this (0)
    i have mysql databse with user info what i want to to do is if a user klicks on view my profile he
    has to see his profile (if he is logged in)so that he kan change some info like email etc. and when
    a user kliks on: view all profiles he has to see a list of users which are links and when he kliks
    on it he goes to the profile of that user. i searched the web but didn't find an snippet or
    tutorial. sooooo does anyone has a code snippet or tutorial ??? thx in advance ....
  11. Some Basic But Important Info About Cancer
    (3)
    Symptoms of Cancer 1. Lumps, especially those that are growing larger gradually, appearing on parts
    of your body such as the breasts, neck abdomen. 2. Signs of injury not externally inflicted which
    do not go away after a long time, such as bruises and scratches on the skin or ulcers on the tongue
    3. Body weight keeps fluctuating or nutrition level decreases dramatically (e.g. falling sick more
    frequently or feel tired easily) despite the absence of sicknesses that also cause such symptoms
    such as Diabetes. 4. Dry cough that does not heal in a long while, blood in phl....
  12. Endif function?
    (6)
    As you get noticed before, I am studying PHP in examples like using the tutorials as well as books
    itself. Through my readings, I get this function CODE <?php endif; ?> a lot of times.
    So, what do you mean by this function, and what does it do exactly?....
  13. Php - Forms, Date And Include
    Working with POST and GET and also the Date() function (0)
    /--------PHP FORMS, DATE AND INCLUDE TUTORIAL BY FLASHY--------\ Hi and welcome to my
    tutorial. I will show you how to make simple PHP forms with the POST and GET statements. I will
    also show show you the Date() function too, aswell as the include() function. OK, so first you need
    a good understanding of HTML, and you need to create your form using that. So lets start off with
    the HTML form. 1. Create a page called form.html. 2. Insert your standard tags like: CODE
    <html> <head> <title>Working with php forms.</title> </he....
  14. User Permission Function [php]
    Determining User Permissions (3)
    There have been several recent request for methods to restrict access to various pages on a web-site
    based on User Permissions in sites that have a Login System in place. Here is some code showing one
    method to restrict access by providing a sub-set of your site's links based on the User's
    permissions. In this demonstration, I have defined a string for each 'level of user'
    determining which set(s) of links they can view on your site. Normal MySql procedure would be to
    read the User's permission level from a record in the database. For the purpose of ....
  15. Tray Info Message
    Kind of popup thingie (7)
    Hi! I'm doing VB for some time now and for last two days I've been looking for a
    tutorial which would show me how to create some kind of notification that would pop up from
    lower-right side of my screen, where the clock is... you know, just like.. when a contact comes
    online on MSN etc. I realized that there's no way to make a balloon pop up like the one in the
    image but is there a way to make anything like that..it doesn't have to be a balloon. A little
    square in the right spot would be good as well /tongue.gif" style="vertical-align:middle" emoid....
  16. My Mum Has Mynesthimia Gravis**
    Does anyone know any info? (2)
    Okay so my mum has this weird muscle disease and she really doesn't share much with me so
    I'm asking anyone who will answer if it's like something that could be life threatening or
    something? I really don't know much about it and I'd like to know more maybe from people
    with experience or something? Just recently she got out of the hospital because her eye kept
    shutting on its own so she had to go and get weird medicines and crap pumped into her for three
    days. =/. ....
  17. Call Of Duty 4
    This is my info about Cod4 (8)
    My Cod4 Review I picked up COD4 kinda hoping for something not like COD and COD2. Both
    previous encounters with the COD franchise were very enjoyable indeed, but the element of a cohesive
    storyline was missing. You were bounced between Russian, English, and American campaigns trying to
    follow each smaller storyline to the end. Boy was I pleasantly surprised with COD4. Blown away is
    more like it. The plot of the game was very well done. The 2 story lines seemed to be going in 2
    different directions at first, but later on you can see the 2 slowly merging in t....
  18. Harry Potter: The Deathly Hallows
    WARNING: MAY INCLUDE SPOILERS! ONLY READ IF YOU HAVE READ THE WHOL (18)
    I was wondering, can this be a discussion for the seventh and final book of the Harry Potter
    series? Because I really want to talk about it. Great book! Do you think that the ending is a
    bit.. predictable? I mean, it was kind of obvious (to me) that Hermione and Ron would
    eventually.. Marry each other? As with Harry and Ginny. But I like Harry's kid the best, the one
    that looks like him. Albus Severus, right? Or was it Albus Snape? Hmm.. I remember it was Albus
    _______.. ....
  19. How To Check If Fsockopen Function Is Enabled?
    (2)
    Hi, I have VPS (virtual private server) and I have access to php.ini file. Is there any script that
    will show that fsockopen function is enabled or where do I have to enable it? Searched google and
    here and couldn't find anything. Thanks! ....
  20. How Good Is This Data Cleaning Function?
    (2)
    Hi all, this is my first function and as part of a script and i just want to know a couple of
    things. here is the code for the function: CODE <? function
    clean($dirty_string) { $muddy_string = stripslashes($dirty_string);
    $murky_string = strip_tags($muddy_string); $clean_string =
    htmlentities($murky_string);      }; ?> So the first thing is how secure is
    it? the script this will be used in connects to a database and sends an email so it needs to stop
    SQL injections and any email ab....
  21. W810
    Post Here All info about this phone (7)
    Hi Dears today i buy W810 , but i think here many user use nokia phones , i *BLEEP* make this topic
    about w810 info ( codes , nice tem ( not free ) , ringtone ( notfree ) , games ( woow i like it ) )
    share your think about w810 phone and options for example my first question is : how can fix w810
    to read wma File /sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" />(
    its very funny its walkman with out read wma file thanks all....
  22. Genuine Help With Smtp And Php Mail() Function
    I need help using the PHP mail() function and the SMTP server on Trap1 (3)
    Hello, I have looked up the solution to this problem numerous times on this forum but cannot seem to
    get a straight answer. I have also read that something called SMTP Authetication is required. I have
    looked up numerous ways this should be done, but I believe it required special protocols. This is
    the code that I tried to use to send e-mail using the SMTP server here at Trap17. CODE
    $email_to = "whoever@whoever.com"; //SEND MAIL TO HERE $subject = "Testing the
    SMTP server"; $message = "This is a test of the SMTP server on T....
  23. Info On The Best Rpg's Coming From The Ps3
    Share your comments (3)
    So far from what i've seen i think that Final Fantasy 13 and Grand theft Auto 4 will be two of
    the best. but that's just my opinion. /biggrin.gif" style="vertical-align:middle" emoid=":D"
    border="0" alt="biggrin.gif" />....
  24. Dell Tech Support
    I just needed a small bit of info (22)
    Ok, so I got my aunt's old Dell Inspiron 8000 laptop. She also gave me a wireless card with it,
    but I had to promise her that I wouldn't connect to the Net until I reinstalled Windows. I
    needed to open the BIOS Setup program to change the boot order of the DVD-ROM drive, but I just
    couldn't figure out how (even hitting Fn+F1, where F1 is marked setup, didn't work, and I
    tried about half a dozen other key combonations, which also failed to work). So this morning I
    called Dell, with hopes of getting my problem solved. The crazy lady whose accent I couldn....
  25. Include File.php?id=something
    using the include() function (13)
    Well, I am making a full CMS system for my site, and want to make the index.php file to include the
    view.php?id=1 file. I tried with this code, but it didn't work: CODE <?php include
    'view.php?id=1' ?> This is the error I get: CODE Warning:
    main(view.php?id=1) [function.main]: failed to open stream: Invalid argument
    in C:\server\xampp\htdocs\test\index.php on line 1 Warning:
    main() [function.include]: Failed opening 'view.php?id=1' for inclusion
    (i....
  26. How To Use A Link To Call Function In Php?
    (8)
    The title says it all, really. How do you call a function using in PHP? I'm doing a project
    and I stumbled upon this problem. I don't want to use query string in the href part like
    since that would mess up the other part of my code. Can anyone pleae help me? I've pasted the
    code below. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Thanksh.
    CODE <?php   function display($x){ //coding goes here.   } ?>
    <html> <body> <p align="center"> <a href="what g....
  27. Php Include Root Ref
    whats the root? (6)
    Every one knows that we can include files in our site, so we have a folder with 2 files, an
    index.php with a menu.php included. But they are on the same folder, what if we wanted to make a
    relative reference for it, so we will always put include("/files/menu.php") and it will always work
    wherever that file is (the file calling the include). Ive had troubles with this, as it doesnt seem
    to be working, i have to change to the dot notation (like ../../../../../files/menu.php) in order to
    keep my includes right. Does any one know what the root is for the include or how can ....
  28. Warning: Virus Spreading Through Msn Messenger
    any info? (12)
    I was online, and then a friend sent me that file, and I accepted it because he's been wanting
    to send me a program that improves the resolution of the screen. But then my email address was in
    the file name, so I asked him what that was. To my horror, he said 'virus', but it was too
    late, I already opened it and then several chat screens popped-up, and it was auto-sent to some of
    the friends on the contact list. Luckily i was quick enough to ask them not to click on it. And my
    norton internet security and microsoft anti spyware program detected it and asked ....
  29. Getting List Of Directories And Files Using Php
    PHP Function for Directory and File List (6)
    is there a php function that lists the content of some folder.... example: /New folder new.txt
    left.gif download.zip dc.exe ....so is there..? /rolleyes.gif' border='0'
    style='vertical-align:middle' alt='rolleyes.gif' /> ....
  30. Need Info For Counter Strike 2 Pls
    Need info for Counter strike 2 pls (13)
    I intend to buy counter strike 2 but I need a few info from experienced users before plunging to
    save some effort. My configuration is P4 (2.4 Ghz) Graphic Card (creative GForce 2 unltra, old)
    Ram 512MB With a low graphic config, can i get the best of it when playing CS2? I heard from
    friends that CS2 needs a relatively high graphic card and cpu.....

    1. Looking for phps, include, function, info, info, include, function

Searching Video's for phps, include, function, info, info, include, function
Similar
PHP Function
To Add
Previous and
Next Page
Feature -
useful php
function
Agent-princi
pal
Relationship
s - some
info on this
important
subject
Plants And
Water Loss -
some info on
growing
plants in
dry
conditions
Enzymes And
Health -
Some
interesting
info on
enzymes
Rate An
Operating
System!
- I need
this info
for my comic
strip.
Reset My
Site Pelase
- read for
more info
Question
Regarding
Php Function
- It's
all about
PHP mail
Yoga - info
about yoga
Php Allow
Url Include
Question!
; - Need an
admin to
clarify
something...
Get User
Info True
Sessions Or
Cookies -
need help on
this
Some Basic
But
Important
Info About
Cancer
Endif
function?
Php - Forms,
Date And
Include -
Working with
POST and GET
and also the
Date()
function
User
Permission
Function
[php] -
Determining
User
Permissions
Tray Info
Message -
Kind of
popup
thingie
My Mum Has
Mynesthimia
Gravis** -
Does anyone
know any
info?
Call Of Duty
4 - This is
my info
about Cod4
Harry
Potter: The
Deathly
Hallows -
WARNING: MAY
INCLUDE
SPOILERS!
; ONLY READ
IF YOU HAVE
READ THE
WHOL
How To Check
If Fsockopen
Function Is
Enabled?
How Good Is
This Data
Cleaning
Function?
W810 - Post
Here All
info about
this phone
Genuine Help
With Smtp
And Php
Mail()
Function - I
need help
using the
PHP mail()
function and
the SMTP
server on
Trap1
Info On The
Best
Rpg's
Coming From
The Ps3 -
Share your
comments
Dell Tech
Support - I
just needed
a small bit
of info
Include
File.php?id=
something -
using the
include()
function
How To Use A
Link To Call
Function In
Php?
Php Include
Root Ref -
whats the
root?
Warning:
Virus
Spreading
Through Msn
Messenger -
any info?
Getting List
Of
Directories
And Files
Using Php -
PHP Function
for
Directory
and File
List
Need Info
For Counter
Strike 2 Pls
- Need info
for Counter
strike 2 pls
advertisement



Php's Include Function (info) - Want info about the include() function?



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE