Tuesday, July 20, 2010

PHP tutorial Part8

Posted by Syarif | Tuesday, July 20, 2010 | Category: |

INSERT THE ANOTHER PAGE on PHP

You don’t have to rewrite the same code in every page in your web if the code is must be declare in every page. You can use INCLUDE or REQUIRE to call the other page, so you don’t have to write on every page the same code.

INCLUDE
to easily know the function of REQUIRE, read the example below.
For example:
Ex1.php:


<?
echo ("this is first page");
?>



Next.php

<?
include "ex1.php"; ?>
<br />
<?
echo ("this is second page");
?>


See? That make you don’t have to write the static code each page.

REQUIRE
Now, how if we change the function from INCLUDE become REQUIRE.
Next.php


<?
require "ex1.php"; ?>
<br />
<?
echo ("this is second page");
?>



The page seems same as INCLUDE function. So, what’s the different?
Let me tell you. How if the page that you call is currently unavailable?

With INCLUDE function:


<?
include "false.php"; ?>
<br />
<?
echo ("this is second page");
?>



The page will show message error, but still execute the page itself.
How about REQUIRE method?


<?
require "false.php"; ?>
<br />
<?
echo ("this is second page");
?>




The page show error message and not execute the page itself.

What function will you use is depend on what information on that page.

Currently have 0 comments:


Leave a Reply