RopeADope Posted January 13, 2011 Share Posted January 13, 2011 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']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/224335-_serverdocument_root-for-navigation-links-wont-execute/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2011 Share Posted January 13, 2011 $_SERVER['DOCUMENT_ROOT'] is a file system path. It only has meaning on the server to the file system and php statements that use file system paths. It is not a URL. A URL is - http://some_domain.com/some_path/some_file.ext Quote Link to comment https://forums.phpfreaks.com/topic/224335-_serverdocument_root-for-navigation-links-wont-execute/#findComment-1158998 Share on other sites More sharing options...
RopeADope Posted January 13, 2011 Author Share Posted January 13, 2011 So how do I go about accomplishing what I'm trying to do? Is there a way to set a document_root-like path to use in URLs? Quote Link to comment https://forums.phpfreaks.com/topic/224335-_serverdocument_root-for-navigation-links-wont-execute/#findComment-1159000 Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2011 Share Posted January 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224335-_serverdocument_root-for-navigation-links-wont-execute/#findComment-1159004 Share on other sites More sharing options...
RopeADope Posted January 17, 2011 Author Share Posted January 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224335-_serverdocument_root-for-navigation-links-wont-execute/#findComment-1160680 Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2011 Share Posted January 17, 2011 You would need to post an example of what you are doing, because I don't think it has anything to do with making links in a navigation menu. Quote Link to comment https://forums.phpfreaks.com/topic/224335-_serverdocument_root-for-navigation-links-wont-execute/#findComment-1160682 Share on other sites More sharing options...
RopeADope Posted January 17, 2011 Author Share Posted January 17, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/224335-_serverdocument_root-for-navigation-links-wont-execute/#findComment-1160690 Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2011 Share Posted January 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224335-_serverdocument_root-for-navigation-links-wont-execute/#findComment-1160699 Share on other sites More sharing options...
RopeADope Posted January 17, 2011 Author Share Posted January 17, 2011 Ohhhh. I did not know that. Just gave it a go and it works! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/224335-_serverdocument_root-for-navigation-links-wont-execute/#findComment-1160704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.