Jump to content

Help with require_once and include commands


Darkmatter5

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'>";

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.