homepage Welcome to WebmasterWorld Guest from 54.226.136.179
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
what is the correct way to say INCLUDE
Flolondon

10+ Year Member



 
Msg#: 12218 posted 2:35 pm on Mar 22, 2006 (gmt 0)

include 'databaseconnect.php'

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

 

ncreegan

10+ Year Member



 
Msg#: 12218 posted 2:41 pm on Mar 22, 2006 (gmt 0)

<?
include('filetoinclude.php');
?>

henry0

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



 
Msg#: 12218 posted 3:17 pm on Mar 22, 2006 (gmt 0)

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

Flolondon

10+ Year Member



 
Msg#: 12218 posted 11:19 pm on Mar 24, 2006 (gmt 0)

thanks

coopster

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



 
Msg#: 12218 posted 12:39 am on Mar 25, 2006 (gmt 0)

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

include_once 'included_file.php';

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved