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

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

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 (2)
  2. 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?....
  3. Arrays Outside A Function
    Need to have arrays available to all functions. (3)
    I've got a bunch of arrays that i want to use for more then 1 function. when i declear the
    arrays outside a function i cant use it in a function. This code was originally written in
    javascript by another person but since I plan to use it and extend it with php I had to change it
    from javascript to php code. In the javascript code the arrays were decleared outside the functions
    with 'var arrayname' I read somewhere that declearing javascript variables with
    'var' gives it global access. Any ideas on how I can go about declearing 1 set of these
    arrays t....
  4. 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! ....
  5. Php Explode Function Help
    (4)
    I am having trouble creating a script, all i want to achieve is to: 1. Select the variable from my
    mysql database, which is in a format of : id|id|id|id| and so on... 2. Split them into separate
    variables by using : $songexploded = explode("|",$ttyo ); 3. Then this is the bit I'm
    stuck on trying to create a while loop from the $songexploded variables. So(this might not be
    correct but you should get the idea).. CODE $x=1; while ($songexploded
    ==$result) echo $songexploded[$x].'<br>'; }....
  6. The Best Zip Function
    (1)
    hi my 6th code is very useful, you can zip your file by this: CODE <? class dZip{     var
    $filename;     var $overwrite;          var $zipSignature =
    "\x50\x4b\x03\x04"; // local file header signature     var
    $dirSignature = "\x50\x4b\x01\x02"; // central dir header signature
        var $dirSignatureE= "\x50\x4b\x05\x06"; // end of central dir
    signature     var $files_count  = 0;     var $fh;          Function
    dZip($filename, $overwri....
  7. Ip Info
    (0)
    Here is my 5th Code: By this class you can have many informations about an IP address: CODE
    <?php class ipinfo {     var $remote_addr;     var $address;     var $country;
        var $state;     var $city;     var $isp;     var $organization;     
        function ipinfo()     {         $this->remote_addr =
    $_SERVER["REMOTE_ADDR"];     }          function check($ip =
    false)     {         if ($ip == false)         $ip =
    $this->remote_addr;         $post....
  8. Mail() Clone
    A PHP mail() function clone (5)
    A lot of free web hosts have disabled the mail() function so you cannot send emails using PHP. Does
    anybody know of a script that makes a function "like" mail but is able to be installed in a web
    accessible directory and called included into another script and called like that? Or maybe you know
    how to make such a function? I just really need to find a way around the free hosts turning of the
    mail() function. I need to figure out a way to send emails.....
  9. [php](simple) Using Functions To Combine Values In A Form
    Really simple example on how to combine values with function (2)
    I just learned this simple method on how to use functions to combine two values from a form. First
    we create ourselves a simple POST form CODE <form method="POST"> Name:
    <input type="text" name="nickname"> Location: <input
    type="text" name="location"> <input type="submit"
    value="Input"> </form> Now we add this php to that same file CODE
    <?php $nick = $_POST['nickname']; $location =
    $_POST['location' ....
  10. [php] Header Function
    (2)
    Header function Greetings we are going to use the header() funtion to redirect start making a
    file called page.php at the top of the file add CODE <?php ?> Example 1 After
    CODE header('Location: http://www.trap17.com'); the LOCATION means
    where you want it to go. Example 2 you also can define a file that you want to redirect to After
    CODE header('Location: index.php'); Example 3 you also can add a timer to
    it /laugh.gif" style="vertical-align:middle" emoid=":lol:" border="0" alt=....
  11. Error With Joomla Template
    cant find function (1)
    Hello! I am working on my template in Dreamweaver and i am using joomla extensions for
    dreamweaver! When i start my page with joomla stand alone server(jsas) i get this errors on the
    bottom of the page! QUOTE Warning:
    mosloadcomponent(w:/www/Joomla/components/com_banner/banner.php) : failed to open stream: No such
    file or directory in w:\www\Joomla\includes\frontend.php on line 66 Warning:
    mosloadcomponent(w:/www/Joomla/components/com_banner/banner.php) : failed to open stream: No such
    file or directory in w:\www\Joomla�....
  12. The Extract() Function
    Something I just found out (6)
    The extract() function is used in PHP to take an array and split it up into variables. MySQL
    queries can be parsed this way. Below is an example. CODE $query =
    mysql_query("select username, password from users where uid=1"); $result =
    mysql_fetch_array($query, mysql_assoc); extract($result); print "Your
    username is : $username"; The extract() function works for ANY array, including
    $_POST, and $_GET. Makes processing form data a LOT easier /biggrin.gif"
    style="vertical-align:midd....
  13. 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....
  14. Explode Function Help
    need help from you programmers! (1)
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Hi I am robert I
    need some help with some php coding. I am stuck with a explode function. Here is the code:
    $username = $check ; $query="SELECT `buildings` FROM `authuser` WHERE
    `uname` = '$username'"; $result=mysql_query($query);
    $result=mysql_result($result,0);
    list($building1,$building2,$building3,$building4,$building5,$building6
    ,$building7,$building8,$building9,....
  15. Mysql 4.0 - Select Max While Joining
    Some general info i wanted to know (0)
    I got a solution using CREATE TEMPORARY TABLE to select MAX things out of a table in reference to a
    Category. Now i want to know that is this CREATE TEMPORARY TABLE available after MySQL 3.23 Server
    intensive. I checked it out on the MySQL Administrator software that monitors your MySQL Software
    and the Load was infact less. But do all the hosts support this. Trap17 does but then too, do hosts
    keep this on or no. I need this for my script. ....
  16. Regexp Function Preg_match_all()
    preg_match_all() - Help me (0)
    Hi, I got a new problem which has caused me to go mad but no solution. preg_match_all() - is the
    problem. I have something like this: CODE [ol] [li]Test1[/li]
    [li]Test2[/li] [li]Test3[/li] [li]Test4[/li]
    [li]Test5[/li] [/ol] Some text.Some text.Some text. [ol]
    [li]Test1[/li] [ol] [li]Test1[/li]
    [li]Test2[/li] [li]Test3[/li] [li]Test4[/li]
    [li]Test5[/li] &....
  17. Question About The Mail() Function
    (2)
    Hi, Is there any way of using the mail() function with an SMTP connection? Is there any way of
    sending messages let's say for example using an email of yahoo? Any help about this woul be very
    thankfull. Thanks in advance.....
  18. How To Enable Mail() Function In Php
    (1)
    im just trying to send mail by using a very simple php function mail() but it is not working.the
    format is CODE $to = "email@example.com"; $subject = "Hi!";
    $body = "Hi,\n\nHow are you?"; if (mail($to, $subject,
    $body)) {   echo("<p>Message successfully
    sent!</p>"); } else {   echo("<p>Message delivery
    failed...</p>"); } I think there is something wrong with php.ini
    setting..maybe something to do with SMTP ....
  19. 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....
  20. 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....
  21. php header() function help needed
    automatic re-direct (4)
    hey ppl, u seem to have real gud knowledge about php, i just wanted a little help...i designed this
    website, but i want that if i click on certain page, it should open for some few seconds and then
    browser should automatically redirect me to some other page....i tried this with header() function
    but i couldnt do the wait n redirect part, ... so somebody plz help.... -thanx in advance!....
  22. Need Help With Php
    GET function with timer (2)
    I need some help on creating a timer that every thirty minutes, refreshes on a URL. I know how to
    get the page, but I have no idea how to create a timer that initiates it. Could someone point me on
    a helpful direction?....
  23. Question For The If And Echo Function
    (2)
    I'm not that good with PHP, and I tried this code: CODE if (
    $_SERVER['REQUEST_URI'] == ('/') )/*'/' is the
    domain root*/ { echo('<img src="{I_ONEURL}" border="0"
    alt="{T_SOMETHING}" />'); } else { echo('<img
    src="{I_ANOTHERURL}" border="0" alt="{T_SOMETHING}" />'); }
    However, it doesn't work. So, basically, I want that if the request is at the root (actually
    mysubdomain.domain.com), it will show {I_ONEURL....
  24. Need Help With The Header() Function
    I am redirecting from my old site (2)
    Over a month ago, I bought a domain name for my site, but my site is still not indexed. I did
    everything needed to get indexed, but I forgot one thing: The old site had exactly the same content
    as the new one. So I had duplicate content. Therefore, I want my old site to redirect the user to
    the new site with this script: CODE <?php header("Location:
    http://www.global-rs.com" . $_SERVER['REQUEST_URI']); exit; ?>
    global-rs.com is my new URL. However, on my old site, which I will be placing this code on, there
    i....
  25. Sending Attachments Using Email Function In Php
    (2)
    I'm trying to send an attachment using the mail Php function. It gets caught by the email
    server with an error. It seems to have a problem with the separator or who knows what. The server
    says something like "invalid separator on mime type." The code is: Code: CODE  // subject
    $subject  = "Hello There "; $mime_boundary =
    "<<<--==-->>>";        // headers        $headers  =
    "From: " . 'Tom' . " <" . 'texample@aol.com' .
    ">\r\n"; �....
  26. Error When Using file_put_contents()
    failed to call to undefined function (4)
    Hey all, I decided to write a script which writes some text to a file, but I have a problem when I
    execute the script, I get a fatal error: QUOTE(homepage) Fatal error : Call to undefined
    function: file_put_contents() in /home/cmatcme/public_html/afile.php on line 55 This is the
    code I'm using to write the file: $ipfnsdoc =
    "/home/cmatcme/public_html/afolder/afile.txt"; if (!is_readable($ipfnsdoc)) {
    echo "File cannot be read"; $stopload = 1; } if (!is_writable($ipfnsdoc)) {
    echo " \nFile can....
  27. Directory Function
    - I need some help (1)
    Hey, I'm really in a jam. Here's whats happening, I have to post over 350 streaming WMA
    files on a server. But it would be nice to not have to script it out in HTML. And I know that in PHP
    you can set a directory or folder and PHP will place all the files out there. Would somone show me a
    way to do that? and please note where I must insert filenames, folder, ect.... So, I have tons of
    files that I need to have on the page, but scrpiting it takes long. Heres the page I'm working
    on: http://www.cbf-wa.org/sermons.php thanx so much....
  28. Need Feedback On A Function
    (1)
    I'm working hard on a fully self-coded community (after tons of errors you get depressed i
    know...but i need to see what i can), so i need some feedback on a Function i made (wich is
    basically reguser.php), here it is: CODE Function regresult($uname, $pword,
    $cword, $rname, $country, $day, $month, $year, $gender,
    $email, $email2){ Global $db; $datab="Users";
    if(empty($uname or $pword or $rname or $country or $day or
    $month or $year or $....
  29. Executing Scripts Without Include() Function
    php function to execute a script w/o showing html markup (3)
    Hi guys. I have another newbish PHP question. /laugh.gif' border='0' style='vertical-align:middle'
    alt='laugh.gif' /> Today, I decided to make a new navigation bar for my site. It doesn't look
    good because I just started learning Flash today, so I was basically feeling my way around the
    application. Anyways, if you use Flash and you try to validate your site at http://w3.validator.org
    , you get a lot of errors for some weird reason. So I was thinking about separating the markup for
    embed Flash from the rest of the site's source code. The problem with that i....
  30. 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' /> ....

    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
Endif
function?
Arrays
Outside A
Function -
Need to have
arrays
available to
all
functions.
How To Check
If Fsockopen
Function Is
Enabled?
Php Explode
Function
Help
The Best Zip
Function
Ip Info
Mail() Clone
- A PHP
mail()
function
clone
[php](simple
) Using
Functions To
Combine
Values In A
Form -
Really
simple
example on
how to
combine
values with
function
[php] Header
Function
Error With
Joomla
Template -
cant find
function
The
Extract()
Function -
Something I
just found
out
How Good Is
This Data
Cleaning
Function?
Explode
Function
Help - need
help from
you
programmers&
#33;
Mysql 4.0 -
Select Max
While
Joining -
Some general
info i
wanted to
know
Regexp
Function
Preg_match_a
ll() -
preg_match_a
ll() - Help
me
Question
About The
Mail()
Function
How To
Enable
Mail()
Function In
Php
Include
File.php?id=
something -
using the
include()
function
How To Use A
Link To Call
Function In
Php?
php header()
function
help needed
- automatic
re-direct
Need Help
With Php -
GET function
with timer
Question For
The If And
Echo
Function
Need Help
With The
Header()
Function - I
am
redirecting
from my old
site
Sending
Attachments
Using Email
Function In
Php
Error When
Using
file_put_con
tents() -
failed to
call to
undefined
function
Directory
Function -
- I need
some help
Need
Feedback On
A Function
Executing
Scripts
Without
Include()
Function -
php function
to execute a
script w/o
showing html
markup
Getting List
Of
Directories
And Files
Using Php -
PHP Function
for
Directory
and File
List
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free 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