Page 1 of 1

$_SERVER problems

PostPosted: 25. January 2012 13:21
by wallspa
HI I am using XAMPP on Windows XP. I am having problems running the script below.

I understand it is to do with the location of files, but I am struggling to resolve.

<?php

// include the layout file
include $_SERVER['DOCUMENT_ROOT'].
'/layout.php';

// Use the myheader function from layout.php
myheader("Welcome to My Website!");

// Include the welcome html page.
include $_SERVER['DOCUMENT_ROOT'].
'/html/index_page.html';

// Include News Index File
include $_SERVER['DOCUMENT_ROOT'].
'/includes/news_index.php';

// Use the footer function from layout.php
footer();
?>

The error output is:

Warning: include(C:/xampp/htdocs/layout.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\myphp\public_html\index.php on line 5

Warning: include() [function.include]: Failed opening 'C:/xampp/htdocs/layout.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\myphp\public_html\index.php on line 5

Fatal error: Call to undefined function myheader() in C:\xampp\htdocs\myphp\public_html\index.php on line 8

Re: $_SERVER problems

PostPosted: 25. January 2012 17:38
by Altrea
Hi wallspa,

Don't reference on $_SERVER['DOCUMENT_ROOT'], because that location can change. It depends on the environment and file structure your system has.
Use relative URLs instead, or set your own base-directory variable and reference to that.

best wishes,
Altrea