Working in the WAMP test server enviroment. I want to be able to register, login and logout from any where in the site, so I included the login form with relative URLS in the header.php file.

This all works fine on the root directory but breaks as soon as you reach any off the subdirectories.

On the root folder
login = http://mytest/login.php 
  
on a subfolder
login = http://mytest/subfolder/login.php/login.php

For each subdirectory I drop to I place a corresponding ../ and it works because it finds the file header.php file. The only problem is the URL actions with the header.php file always have an extra folder attached which doesn't exist.

I have tried

<?php require_once( str_replace('//','/',dirname(__FILE__).'/') .'../header.php'); ?>

and I still get the same results

Is there any fnction to stop PHP parsing the included file as the same as the current file in process?

Member Avatar for diafol

if you use an absolute path, it should be ok. $_SERVER has problems on certain servers though, but I've never experienced any:

$root = $_SERVER['DOCUMENT_ROOT'];

include("$root/myfolder/header.php");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.