Skip navigation
Currently Being Moderated

PHP Includes

Sep 10, 2011 4:40 AM

Hi!

 

I'm just playing around with PHP includes but getting all confused with the links.

 

Am I correct in saying that I have to use root relative links now? If there are images in the include files they need to be linked relative to the root?

Also - the code on the page which includes in the include file needs to find the include file with a root relative reference?

If we use document relatives then I will have to keep manually changing the code?

 

if this is right - which I'm not sure that it is - then why is it that when I do this it isn't working? Is it because Dreamweaver isn't uploading the include files onto my testing server? Or is there another problem?

 

Thanks!

 

Chris

 
Replies
  • Currently Being Moderated
    Sep 10, 2011 9:57 AM   in reply to cripaustin

    Am I correct in saying that I have to use root relative links now? If there are images in the include files they need to be linked relative to the root?

     

    Yes.

     

    Also - the code on the page which includes in the include file needs to find the include file with a root relative reference?

     

    Doesn't matter, as long as the link is correct.

     

    Is it because Dreamweaver isn't uploading the include files onto my testing server?

     

    Check to see if it's there.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 10, 2011 10:07 AM   in reply to MurraySummers

    Also, if there is any question that the script cannot find the include file, change include() to require(). You will get an error if require can't find it, but include will not give an error.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 10, 2011 12:45 PM   in reply to cripaustin

    Just to clarify, you don't need to change your site definition to root relative links. But any links within the include file itself should be root relative. Someone, please confirm or correct this!

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 10, 2011 12:50 PM   in reply to Lon Winters

    They only need to be root relative IF -

     

    1.  The include files are kept within a folder of the site (mine are always in a folder called "_inc").

    2.  The site, itself, contains multiple folder levels which contain parent files for these includes.

     

    If everything were at the root level of the site (i.e., no folder hierarchy) then document relative links would work throughout.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2011 5:18 AM   in reply to cripaustin

    So I've researched this further and from what I understand - the include PHP statement won't understand the root releative link reference.

     

    No PHP command will understand a root relative link, unless you amend it as follows -

     

    <?php include($_SERVER['DOCUMENT_ROOT'] . '/the_path_to_the_include_file.php'); ?>

     

    The reason you must do that is that Apache's root is not the same as the site's root, and when Apache sees the leading "/" it goes to its own root.

     

    Anyone have a quick fix? How do I use PHP to find the same file (with a root relative ref) using the include statement? I don't want to have to change the include statement for every page.

     

    You are still confused, I'm afraid.  The link to the include file is a document relative link, e.g.,

     

    <?php require_once("path_to_include_file.php"); ?>

     

    or it's an appropriately adjusted root relative link (as described above).

     

    The links IN the include file are root relative -

     

    <a href="/path_to_linked_file.php">Go to this linked file</a>

     

    Also: What do people think to using dreamweaver templates with PHP includes - so keep all the CSS link refs, PHP includes, etc in a template and then apply the template to each new page...this way you get the best of both worlds-?

     

    It's a technique I use on nearly every site I build.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2011 8:18 AM   in reply to MurraySummers
    function(){return A.apply(null,[this].concat($A(arguments)))}

    Also: What do people think to using dreamweaver templates with PHP includes - so keep all the CSS link refs, PHP includes, etc in a template and then apply the template to each new page...this way you get the best of both worlds-?


    Murray responded by saying he uses this on nearly every site he builds. I will provide a different perspective.

     

    I have not touched Dreamweaver templates since I discovered includes four years ago.  I use includes and classes for frequently used elements, but my primary method is to build sites that only have one to six pages because the content is all stored in the database. I have a few websites that have only a single page. The admin systems of these sites may contain many pages, but the actual "website" only consists of one to six pages. This is similar to how frameworks like ZENDframework.

     

    Using this method, there is no difference between a template and the actual pages. PHP conditional statements can be used to handle many differences between content and presentation.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2011 8:48 AM   in reply to cripaustin

    Reasonable questions.

     

    Search engines have no problem with dynamically generated websites. It is possible to cache the pages (generate them ahead of time), but this is done for performance purposes only on sites that get tons of traffic.

     

    So when someone comes to the website, there actually are not pages there. It all gets built on the fly. The server can build a complex page with many calls to the database instantly. It's a beautiful thing.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2011 1:46 PM   in reply to cripaustin

    Murray already said it, but I'd like to reiterate, I guess I just feel like typing.

     

    The path TO the include file is document relative. Any links within the include file, like references to images, should be root relative. This means that you can include the include file in any page regardless of it's location, and any images or other links will follow along. The only problem that may present is when you call another include file from within the original include, then you need a more defined and consistent folder structure like Murray's set up.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 12, 2011 4:03 AM   in reply to cripaustin

    The way I work is to make all links in include files an 'absolute path' when I work locally and then do a 'find and replace' in Dreanmweaver substituting the local path with the actual domain name just before I upload the finished site.

     

    So this (locally)

    <p><a href="http://localhost/site_name/index.php">index</a></p>
    <p><a href="http://localhost/site_name/pages/eastbourne.php">Eastbourne</a></p>
    <img src="http://localhost/site_name/images/eastbourne.jpg" width="200" height="170" alt="Eastbourne Seafront" />

     

    Becomes (remote)

    <p><a href="http://www.domainName.com/index.php">index</a></p>
    <p><a href="http://www.domainName.com/pages/eastbourne.php">Eastbourne</a></p>
    <img src="http://www.domainName.com/images/eastbourne.jpg" width="200" height="170" alt="Eastbourne Seafront" />

     

     

    Not sure if this is the best way but if I have 'includes' which need to be included into documents both at root level and in directories seems to work efficiently for me.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 12, 2011 4:08 AM   in reply to osgood_

    Using virtual hosts locally solves that issue.  But your method is a good workaround, too.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 12, 2011 4:16 AM   in reply to MurraySummers

    Murray *ACP* wrote:

     

    Using virtual hosts locally solves that issue.  But your method is a good workaround, too.

     

    Never set virtual hosting up before is that complicated?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 12, 2011 4:24 AM   in reply to osgood_

    Nope.  David Powers tells you how to do it in his book on CS5.  Pretty simple.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 6:41 AM   in reply to cripaustin

    The spiders are requesting the pages just the same way you as a visitor do.  As far as they/you know, the page is a complete, static page sitting on the server waiting for you to request it.  But the server knows better....

     

    I'm not aware of any tutorials for how to create a "mini-CMS" site, other than tutorials on how to use server scripting to retrieve data from a database and display it on a page.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 6:42 AM   in reply to cripaustin

    Like many others here, I build sites that have hundreds of "pages" that change frequently and are maintained by non-technical staff. the dynamic method makes this possible. This is how virtually every large website is built, and most (but not all) are based on PHP/MySQL/Linux.

     

    A lot of people get a solid foundation in PHP from David Powers' books. Kevin Yank wrote a book called Database driven Websites using PHP and MySQL which is a good place to start for the kind of thing you are asking about. The Yank book is an easy breezy introduction, but it doesn't always use best practices. It gives you a practical overview with the gratification that you actually build something. I only have one of Powers' books, but I think I can generalize that he gives you a deeper comprehsion and uses better methods, but it takes more effort to work through his books. So I would say start with Yank, but with the understanding that you will need to continue on to one or more of the Powers books.

     

    To answer your question "does the dynamic method affect search rankings?" Different people will give widely different answers to that, but the short answer is that you are NOT penalized for using dynamic structures, which is the way all serious websites are built these days. Some people will say that you have to rewrite your urls to make them "SEO friendly" but Google has formally stated that this is almost never makes a difference and may actually hurt you.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 6:55 AM   in reply to Rob Hecker2

    but Google has formally stated that this is almost never makes a difference and may actually hurt you.

     

    Do you have a citation for this, Rob?  My experience is not strong in this area, but logic tells me that a link like this -

     

    http://www.example.com/keyword/keyword.php

     

    will inherently rank better than a link like this -

     

    http://www.example.com/?id=5&whatever=foo

     

    And it seems that would be true even if you are doing a 301 redirect from the former to the latter.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 7:29 AM   in reply to cripaustin

    P.S. Also just found this http://www.webconfs.com/dynamic-urls-vs-static-urls-article-3.php

     

    Thoughts?

     

    That's exactly the discussion we have just been having.  Consider, for example, this page -

     

    http://www.theloftbroker.com/property/greenwich

     

    If you visit that link, you will find this URL in the browser's address field when the page loads -

     

    http://www.theloftbroker.com/indiv-detail.php?id=1

     

    What is happening is exactly what is described in the link you provided. 

     

    If you would visit all of the properties on that site, you will see that *all* of them are being displayed by that single page (indiv-detail.php).  And that's how the no-page (or more accurately, single-page) site works....

     

    Why don't all sites use this method?  It's just another level of complexity for the developer to surmount.  And some sites' content doesn't map well into a data table of fields.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 7:51 AM   in reply to MurraySummers

    Murray *ACP* wrote:

     

    P.S. Also just found this http://www.webconfs.com/dynamic-urls-vs-static-urls-article-3.php

     

    Thoughts?

     

    That's exactly the discussion we have just been having.  Consider, for example, this page -

     

    http://www.theloftbroker.com/property/greenwich

     

    If you visit that link, you will find this URL in the browser's address field when the page loads -

     

    http://www.theloftbroker.com/indiv-detail.php?id=1

     


     

    You should also say that the page is basically a template. If you just add the id=2 on the end of the link you get to another 'identical' page but with different information set out in the same way.

     

    http://www.theloftbroker.com/indiv-detail.php?id=2

    The pages of the site which do not conform to the template layout still have to be produced individually:

     

    http://www.theloftbroker.com/about.html

     

     

    So to clarify. If you have a lot of pages which carry the same basic information for different products then a database is a more steamline workflow to cut down on the number of pages you have to maintain.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 8:06 AM   in reply to osgood_

    Bingo.  Of course, you still have to maintain the info in the database....

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 8:16 AM   in reply to osgood_

    OK, this conversation is heating up but I for one have to get busy with work today, so I may hav eto drop out, at least for a while.

     

    Marray, I am sure I bookmarked the source of the info regarding rewrites. It came from the blog of a top Google manager. When I find it I will create a new post and name it something like "Murray, rewrite SEO issue."

     

    I am not a SEO expert but have of course been involved in several SEO projects, collaborating with experts (both real and, uh, not so real). My overall conclusion is that.

     

    1. SEO is a moving target and what was true last year may be completely untrue this year. I think the rewrite issue falls into that category.

     

    2. Content is king. To win status with Google, create a site people will flock to for the information it provides.

     

    3. Second to content is organization that the bots can make sense of. For instance, use H1 tag for main headers, and use descriptive titles and subtitles, etc.

     

    4. Links are next in importance, but make sure they are REAL links, not links to SEO link farms.

     

    5. Trying to cheat by making Google think your site is something it is not will likely backfire.

     

    The above is a simplification, and there are many other aspects, but as the SEO fads have come and gone, the above always holds true.

     

    Regarding the other general discussion, of when to use dynamic methods. If you already know how to build them, then I think it makes sense to use them for even very tiny websites.It is always a requirement to use the dynamic approach if you are building a site for clients to maintain through a web interface. For small sites that you manage yourself, you can leave out many of the web-based administration niceties.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 8:27 AM   in reply to Rob Hecker2

    Thanks, Rob - I couldn't take issue with any of the points you listed....

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 8:42 AM   in reply to MurraySummers

    Murray, I just found that url to the static/dynamic question. Here it is:

     

     

    http://googlewebmastercentral.blogspot.com/2008/09/dynamic-urls-vs-sta tic-urls.html

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 9:32 AM   in reply to cripaustin

    Isn't this basically the way Wordpress works? If you look at the source, very few pages contain actual content of any sort, it's all generated on the fly. What it does use however are "template" type pages for page types, some are part of the WP source and some are part of the theme.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 9:56 AM   in reply to Lon Winters

    Yes, it is exactly how WordPress works. (And Drupal and Joomla)

     

    WordPress themes are significantly differnt from Dreamweaver templates. WP themes are integrated into the database and even, sometimes, to the business logic. Overall, though, it's very hard to implement your business logic into a WP site.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 11:16 AM   in reply to Rob Hecker2

    Thanks.  I note that the date on the article is 2008.  And I note some fairly critical responses.

     

    Seems to me that my argument still applies, too.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 11:42 AM   in reply to MurraySummers

    Well, I think that what the article makes clear is that you are not doomed if you are not using rewrites, that GOOGLE does not penalize dynamic urls, and and that there are various considerations. So yes, your point is valid, but the situation is more complex than some people treat it.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2011 1:33 PM   in reply to Rob Hecker2

    Definitely - but I figure this way: if you are passing up an opportunity to LEGALLY sneak keywords into semantic markup, then you are missing at least a part of the boat.  This is a way to do that, e.g.,

     

    http://www.example.com/keyword1/keyword2

     

    redirects to

     

    http://www.example.com/foo.php?id=23&whatever=foo

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points