Base code for PHP

Hi, im starting out in PHP and iv come to a problem where i would have a .php file in a sub folder and it would only read other .php files from the folder it is in. Is there a way where i can tell the .php file to look in the main folder for the other files? Like how HTML has:<base href="url" /> is there the equivalent for PHP?

Well, if you’re using include or require, you’d just back it up like with any other tag. to back up one folder, you’d just use …/, so if your php file is in folder2, but you want to get a file in folder1, you’d do include “…/file.php”;

Richei’s answer is perfectly acceptable, however as an alternate, try this:

[php]include $_SERVER[‘DOCUMENT_ROOT’] . ‘/some_dir/another_dir/file.php’;[/php]

obviously you need to change the ‘some_dir/another_dir/file.php’ bit to point at the file you want to include.
The $_SERVER[‘DOCUMENT_ROOT’] bit will start in the root folder (public_html) then follow whatever path you add to it. This method works regardless of whatever dir your in when calling the included file.

Hope that helps,
Red :wink:

@Richei I did not know about “…/” thanks for the info. And yes it works great now.
@Redscouse Im having trouble trying to get that to work, but its ok imma use the “…/”.
Thanks for the help you two.
yes i am blindsniper but i decided to make an account under this name.

even one more way of doing it…[php]<?php require_once dirname(__FILE__) . "/includes/header.php"; ?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service