1

I have the following folder structure:

  • website.com/index.php
  • website.com/page/asd.php
  • website.com/header.php
  • website.com/js/file.js

header.php contains:

<script src="js/file.js"></script>

index.php contains:

include_once 'header.php';

asd.php contains:

include_once  $_SERVER['DOCUMENT_ROOT'] . '/header.php';

So file.js will work on index.php, but file.js doesnt work on asd.php. On asd.php the browser want to get /pages/js/file.js (which doesnt exist) and not /js/file.js

How can I handle this problem? Thank you.

John
  • 63
  • 1
  • 7

1 Answers1

0

Start path of your file with /

<script src="/js/file.js"></script>

This will tell browser to look from the root directory.

vanowm
  • 9,466
  • 2
  • 21
  • 37