Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11601

Base Location for PHP

$
0
0

I recently decided to incorporate PHP into my website, but I've never worked with it before so I'm not familiar with the functions...

My problem is that I am using the include() method for my header and footer on each PHP page like this:

<?php include('../php/header.php'); ?>

This navigates from /public_html directory to the /php directory in the root of my website. To account for the different sub-directory levels that files may be located, at the top of each PHP page I add:

<?php/* Path prefix so relative links work correctly */ $path = "../";?>

and ../ could be replaced with ../../ for a file another sub-directory down and so on, and in the header and footer files, links are preceded like this:

<a href="<?php echo($path); ?>index.php" title="Home">Home</a>

and everything works fine like this...until I try to use it with wordpress which is located in a sub-directory on my website. Wordpress uses dynamic pages and so sometimes pages are located in a sub-directory lower than other pages and the links will fail to work with this method. In my old site design, I used the tag to set all link references to the root/public_html directory of my site. However, PHP is not affected by this tag. What I need is a method to set the the link references from the /public_html directory for my include() methods on the blog.

Is there such a method or is there a better way to do what I am doing?


Viewing all articles
Browse latest Browse all 11601

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>