0

I've playing with a very simple setup: index.php with a header.php in the same directory. I've tried all the ways to include the header.php into my index.php but I still get a 500 - Internal Server Error.

So I tried the most fool-proof method and only coded this into my index.php

<?php
include("http://mywebsite.com/header.php"); 
echo "index";
?>

Then in my header.php I only coded

<?php echo "header"; ?>

I cannot figure out whats causing the problem. I've included an absolute path to the header. When I remove the include function the 500 error is no longer an issue.

I'm running my site using GoDaddy with a Plesk/Windows platform if that makes any difference?

sebjwallace
  • 753
  • 1
  • 8
  • 17
  • RTFM: If the header.php is in the same directory as the index.php then remove domain name. Only file name like `include("header.php");` is enough. [More](http://php.net/manual/en/function.include.php) – Dipen Shah Aug 13 '15 at 19:06

2 Answers2

2

Try this:

<?php 
   $path = $_SERVER['DOCUMENT_ROOT'];
   $path .= "/header.php";
   include_once($path);
?>

see: PHP include absolute path

Community
  • 1
  • 1
samland
  • 192
  • 1
  • 12
  • That's interesting, although I think I'd tried this before it seems to have worked. I've echoed $path and I got a rather different looking path beginning with the drive letter. – sebjwallace Aug 13 '15 at 19:12
  • Sometimes, even the smallest details make all the difference. – samland Aug 14 '15 at 12:09
0

Try this:

Contents of index.php:

<?php 
include 'header.php';
echo 'index';
?>

Contents of header.php:

echo 'header';