Jump to content
xisto Community
thablkpanda

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

Recommended Posts

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.

 

<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

Share this post


Link to post
Share on other sites
<?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.. :D

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites

^^^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..

<?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://forums.xisto.com/no_longer_exists/ IF IT IS IN THE 'WWW' FOLDER. THAT MAY NOT BE THE LINK TO YOUR SITE FOR ALL USERS!****

Share this post


Link to post
Share on other sites

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()

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

46973[/snapback]


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... :D )

 

LOL

Panda Out :D

Share this post


Link to post
Share on other sites

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.

 

<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

46109[/snapback]

This person is right

 

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).

46282[/snapback]

Share this post


Link to post
Share on other sites

By This Fun you can load many page in your page without iframe

and you can call many data in your page

for example ::

my index.php code is ::

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://forums.xisto.com/no_longer_exists/;

<html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?php include(Your 2nd Page For Load with localhost Address); ?></body></html>
thanks All ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.