Welcome to Dream.In.Code
Become a PHP Expert!

Join 137,429 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,893 people online right now. Registration is fast and FREE... Join Now!




include

 
Reply to this topicStart new topic

include

myharshdesigner
6 Jan, 2008 - 05:39 PM
Post #1

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 24


My Contributions
i wana know what is the difference between server side includes and simple include function in php ?
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Include
6 Jan, 2008 - 08:17 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,260



Thanked: 227 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
PHP uses the include() function to include other files filled with code into the executing page. So for instance you can create a file which has code to connect to a database and save it as database.php. Then on every page you are coding (be it the login page, admin page, or whatever) you can then include the code from database.php in the page like so....

CODE

include("database.php");

// More code for our login page goes here utilizing the functions
// found in database.php.


The file database.php is said to be a server-side include because it is then included in your other pages using the include function.

Another example would be having a file called "sayhello.php" with a function like...

CODE

<?php
function sayhello() {
     return "hello there everyone!";
}
?>


Then in our welcome page called "welcome.php" we would include the sayhello.php file so we get access to the function.

CODE

<?php
// welcome.php

include("sayhello.php");

echo "This is my greeting: " . sayhello();
?>


In the welcome.php page we included a server-side include called sayhello.php and then used the function from that file as if we had defined the function right in the page.

This makes it easier for us to have modular reusable code fragments which we can include in several pages at once.

Hopefully that makes some sense.

Enjoy!

"At DIC we be include loving code ninjas!" decap.gif

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 04:54AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month