Welcome to WebmasterWorld Guest from 54.145.80.57

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

what is the correct way to say INCLUDE

     
2:35 pm on Mar 22, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Feb 3, 2003
posts:279
votes: 0


include 'databaseconnect.php'

whats the correct way to say include within another fie..please help

2:41 pm on Mar 22, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Apr 8, 2004
posts:215
votes: 0


<?
include('filetoinclude.php');
?>
3:17 pm on Mar 22, 2006 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts:4393
votes: 2


<?php
include($_SERVER['DOCUMENT_ROOT'].'/whatever.php');
?>
OR
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/whatever.php');
?>

Here you are supposed to have a file named whatever.php at root level (where is located your index file)

Using one or the other method allows you for not worrying about changing the include path within many different directories

It is a better practice to use include_once VS solely include, reason is that
You might create a problem when using files that includes files and could include the same inclusion many times thus generating an error
For example if you use a function to connect with your database such as
db_conn(); you might run in an error that will state “cannot REDECLARE function db_conn, already declared in whatever.php line 3333”

11:19 pm on Mar 24, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Feb 3, 2003
posts:279
votes: 0


thanks
12:39 am on Mar 25, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


Unless you are contributing code to PEAR. They have their own coding standards [pear.php.net]:

include_once 'included_file.php';