Jump to content

$_SERVER['DOCUMENT_ROOT'] for navigation--Links won't execute


RopeADope

Recommended Posts

Hi all.

 

Working on a nav system using the document_root variable.  I can't figure out why the links won't execute when I click them.  When I mouse over a link, it shows the correct URL, but nothing happens when I click the links.  The browser remains on the same page.

 

The page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
      <title>vCTO-Home</title>
      <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
     <?php include($_SERVER['DOCUMENT_ROOT'] . '/php/var.php');?>
   </head>
   <body>
      <?php include($_SERVER['DOCUMENT_ROOT'] . "/php/t1.php");?>
   </body>
</html>

 

t1.php

      <div class="tier">
         <a href="<?php echo $docroot;?>/index.php">Home</a>
         <a href="<?php echo $docroot;?>/demand_management.php">Demand Management</a>
         <a href="<?php echo $docroot;?>/engineering.php">Engineering</a>
         <a href="<?php echo $docroot;?>/steady_state.php">Steady State</a>
         <a href="<?php echo $docroot;?>/communications.php">Communications</a>
         <a href="<?php echo $docroot;?>/business_management.php">Business Management</a>
         <a href="<?php echo $docroot;?>/risk_management.php">Risk Management</a>
         <a href="<?php echo $docroot;?>/other.php">Other</a>
      </div>

 

var.php

<?php
$docroot=$_SERVER['DOCUMENT_ROOT'];
?>

Link to comment
Share on other sites

A leading slash / on a URL, makes it a domain-root relative URL, which most browsers support. They take the http://some_domain.com of the current page and append the domain-root relative URL to it.

 

If you want to form a fully qualified/absolute URL, you can either setup a configuration variable/constant to hold your domain or you can use $_SERVER['HTTP_HOST'] to get it at runtime to make the - http://some_domain.com/some_path/some_file.ext URL.

Link to comment
Share on other sites

So I thought I had this figured out but I've run into another problem.  I tried using a leading "/" which worked initially, but I've found that with documents that are in directories, I can only load files in parent folders by using "../".  I also tried using $_SERVER['HTTP_HOST'] instead of the leading slash but that hasn't worked.

Link to comment
Share on other sites

The code that I'm showing here is from a file in /input and the includes are for files in /php

 

This code:

<html>
   <head>
      <title>vCTO-Service Portfolio Input</title>
      <?php include('/php/head.php');?>
   </head>
   <body>
      <?php include('/php/t1.php');?>
      <?php include('/php/t2_demand_management.php');?>
      <?php include('/php/t3.php');?>
   </body>
</html>

 

Produces these errors:


Warning: include(/php/head.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\input\input_service_portfolio.php on line 5

Warning: include() [function.include]: Failed opening '/php/head.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\input\input_service_portfolio.php on line 5

Warning: include(/php/t1.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\input\input_service_portfolio.php on line 8

Warning: include() [function.include]: Failed opening '/php/t1.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\input\input_service_portfolio.php on line 8

Warning: include(/php/t2_demand_management.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\input\input_service_portfolio.php on line 9

Warning: include() [function.include]: Failed opening '/php/t2_demand_management.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\input\input_service_portfolio.php on line 9

Warning: include(/php/t3.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\input\input_service_portfolio.php on line 10

Warning: include() [function.include]: Failed opening '/php/t3.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\input\input_service_portfolio.php on line 10

 

This code produces no errors:

<html>
   <head>
      <title>vCTO-Service Portfolio Input</title>
      <?php include('../php/head.php');?>
   </head>
   <body>
      <?php include('../php/t1.php');?>
      <?php include('../php/t2_demand_management.php');?>
      <?php include('../php/t3.php');?>
   </body>
</html>

Link to comment
Share on other sites

Navigation links deal with URLs that the browser requests. Php include statements deal with file system paths that php uses to open and read a file. Links and include statements don't have anything to do with each other.

 

You WOULD use $_SERVER['DOCUMENT_ROOT'] to form an absolute file system path to use in an include statement. A leading / on a file system path refers to the root of the current disk drive.

Link to comment
Share on other sites

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.