Technology, Web & Business Forum

You are here: Technology, Web & Business Forum : Web Development : Programming : How to get a PHP file to be included across files in different directories?


Welcome to the Technology, Web & Business Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.


Programming Discuss programming languages such as .NET, PHP, PERL, ASP, ColdFusion, C++


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-22-2009
Junior Member
 
Join Date: Nov 2009
Posts: 3
Default How to get a PHP file to be included across files in different directories?

Hi,

Currently I have created some php based webpages and uploaded them to my web hosting server.It has a PHP 5.1.6
installed.With this I am able to include files only that are in the same directory(they work well using require() fn).If not an error message displaying some "no such file" in directory appears in the page.I would like to use them to be included in different direcetories.What should I do?
Reply With Quote
  #2 (permalink)  
Old 11-23-2009
Junior Member
 
Join Date: Nov 2009
Posts: 5
Default hai

create the directories and include the names when using the require() function.

example :

your index.php is in the root directory
/index.php
and you have a directory with your other php files in
/lib/other.php

so in index.php you will have

require("lib/other.php");
Reply With Quote
  #3 (permalink)  
Old 01-13-2010
Junior Member
 
Join Date: Jan 2010
Posts: 3
Default hai

Yes thats right you could use a require() method and specify the path of the file to call or else you could use the include method. For example

vars.php
<?php

$color = 'green';
$fruit = 'apple';

?>

test.php
<?php

echo "A $color $fruit"; // A

include 'vars.php';

echo "A $color $fruit"; // A green apple

?>
__________________
online Christian scholarships
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 07:17 PM.