homepage Welcome to WebmasterWorld Guest from 54.211.7.174
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
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




msg:1265168
 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




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

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

henry0




msg:1265170
 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




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

thanks

coopster




msg:1265172
 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