$_SERVER problems

Problems with the Windows version of XAMPP, questions, comments, and anything related.

$_SERVER problems

Postby wallspa » 25. January 2012 13:21

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
wallspa
 
Posts: 1
Joined: 25. January 2012 13:16
Operating System: Windows XP

Re: $_SERVER problems

Postby Altrea » 25. January 2012 17:38

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
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8288
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 72 guests