Jump to content

Recommended Posts

How can I change the following code so that regardless of where the code is directory wise on the site, it'll always push all the way back to the root of the site directory structure to find the files?  I tried this, but didn't work.

 

$color="white";
echo "<link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "config.css' rel='stylesheet' type='text/css'>
  <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "divs.css' rel='stylesheet' type='text/css'>
  <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "forms.css' rel='stylesheet' type='text/css'>
  <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "links.css' rel='stylesheet' type='text/css'>
  <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "tables.css' rel='stylesheet' type='text/css'>
  <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "nav.css' rel='stylesheet' type='text/css'>";

$_SERVER['DOCUMENT_ROOT'] is a file path on the server. It has no meaning when used in a link (or anything else that is rendered in a browser.)

 

A leading slash / on a relative link refers to the domain root.

I just realized I didn't actually ask anything in regards to require or include.  The answers to my first question worked great, so here's a new one.  Here's an example directory structure

 

public_html (folder)

  index.php

  library (folder)

    funcs.php

  forums (folder)

    index.php

    library (folder)

      forum_funcs.php

 

public_html/index.php

<?php require_once('/library/funcs.php'); ?>

 

public_html/forums/index.php

<?php
  require_once('/library/funcs.php');
  require_once('/library/forum_funcs.php');
?>

 

This obviously produces an error in public_html/forums/index.php where it reports it can't find '/library/funcs.php'.  How can I change the code for it to find the file?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.