0

I have a simple goal but I'm having some issues. To save on bandwidth, I'm attempting to make "index.php" load up the separate parts of the page and then when people select areas of the site from the navbar, JUST the middle content changes.. As it stands, the files just have an echo statement to see if anything shows up - but nothing so far. I read about server side includes but I thought that I might be able to do it strictly with PHP. Is this a proper way to address my goal? What am I missing here? Do you need more info? Thanks so much for your time and help! :D

index.php

<html>
<body>
<?php include 'header-navbar.php' ; ?>
<?php include 'content.php' ; ?>
<?php include 'footer.php' ; ?>
</body>
</html>
user3942918
  • 25,539
  • 11
  • 55
  • 67
adraedin
  • 27
  • 1
  • 6
  • 1
    This is great idea for organization and maintainability, but I don't think it will save any bandwidth. The server will serve the same content regardless of how PHP constructs the page. To change page content without reloading the entire page, you may want to consider using [AJAX](https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started). – showdev Mar 11 '15 at 19:53
  • 1
    Checked your error logs to see why nothing shows up? Also, SSI = server side *include*. – j08691 Mar 11 '15 at 19:55
  • @showdev Okay, bandwidth aside - Is this a simple way to do it? As far a code goes - why doesn't that^ work? – adraedin Mar 11 '15 at 19:55
  • As j08691 suggested, check your server's error logs. Are you sure you're including the correct path and file name? Is PHP working on your server? Perhaps [PHP's error reporting](http://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings#answer-5438125) will give you a clue. – showdev Mar 11 '15 at 19:56
  • @j08691 oops, fixed that typo. and as far as "error logs" go - I don't know about ~that stuff~ just yet, that's another bridge I'll cross soon. – adraedin Mar 11 '15 at 19:57

2 Answers2

0

You are kind of mixing concerns here. PHP shouldn't be concerned about the display on the client. That is the job of the HTML, JS, CSS, etc. To achieve what you are asking for you should read up on AJAX. It will allow you to load / reload specific sections of the page on the client without refreshing the entire page.

The thing you need to keep in mind is that regardless of what you cache at the server the same content is going to be sent back for the page. Anything you cache on the server side will have no effect on the amount of bandwidth used to load the page.

aronkerr
  • 314
  • 3
  • 14
0

This will not save on bandwidth. These days if you are not serving video,downloads, or do not have monster traffic then bandwidth should be a minimal concern. Basic Godaddy (not an endorsement) accounts are $5 a month and have "unlimited" bandwidth. Obviously unlimited is more a marketing term but you can safely do 10 GB of traffic without any issues. Which is a lot of web pages.

greg_diesel
  • 2,955
  • 1
  • 15
  • 24