Page 1 of 1

Is it okay to always link to the full URL?

Posted: Thu Dec 09, 2010 4:30 am
by condoravenue1
Hello, I am creating a site that has a navigation bar at the top that never changes. I get the navigation bar into the html code by using <?php $file = file_get_contents ("navigation_code.php"); Echo $file;?>. I recently created some folders to organize my files, and that caused all the links to be broken. So to fix this, i just used the full url for every link in my whole site. Rather than href = "home.php" it now says href = "http://mysite.com/home.php." This fixes the problem.

My first question is, is there anything wrong with doing it this way (href = "home.php" changed to href = "http://mysite.com/home.php.")? I read something about how this affects the caching process, I didn't uderstand it.

My second question is, is this way (php - get_file_contents()) of creating sitewide content good practice? It works great, and editing my site's navigation/header/footer is quick; I change one file and the whole site is adjusted perfectly. Does this make the page load faster or slower? Is there anything else that I should know?

Thanks for all the help.

Re: Is it okay to always link to the full URL?

Posted: Thu Dec 09, 2010 9:53 am
by pickle
1) The only thing potentially wrong with is what happens if your domain name changes? If that's not going to happen, there shouldn't be a problem. I can't imagine how it would negatively affect caching
2) Having common files for various parts of your site is a good idea - for the exact reason you state. However, I wouldn't do it the way you do it. With your method, you can't have PHP code execute in the file you're referencing. Just use a simple include() call instead.

Example:

title.php (file to be included)

Code: Select all

<?PHP
  echo $_SESSION['user']['title'];
?>
file to display

Code: Select all

//your method
Welcome <?php $file = file_get_contents('title.php'); echo $file; ?>

//using include()
Welcome <?php include 'title.php'; ?>
resulting output
[syntax]//your method
Welcome <?PHP
echo $_SESSION['user']['title'];
?>

//include method
Welcome Mr. Anderson[/syntax]

Re: Is it okay to always link to the full URL?

Posted: Thu Dec 09, 2010 11:58 pm
by condoravenue1
Will using this include() function cause the loading time to be slower than if i just use normal HTML with out the external file?

Re: Is it okay to always link to the full URL?

Posted: Fri Dec 10, 2010 9:41 am
by pickle
Technically yes. It's such a small amount though that you won't even be able to time the difference. This is a pretty standard practice - I wouldn't worry about any negative time effects.