Welcome to WebmasterWorld Guest from 184.73.126.70

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)

10+ Year Member



include 'databaseconnect.php'

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

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

10+ Year Member



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

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



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

10+ Year Member



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

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



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

include_once 'included_file.php';

 

Featured Threads

Hot Threads This Week

Hot Threads This Month