Results 1 to 4 of 4
  1. #1
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using Server-Side includes with PHP

    I played with this for a long time before throwing in the towel and hardcoding some things into my PHP templates. Using Apache, one can perform a Server-Side Include with this syntax:<pre>< ! - - #include virtual="somefile.htm" - - ></pre>

    and whammo, you're off to the races. (spaces added to prevent the Lounge from seeing that as a true comment.) That is, as long as you name the resulting document SHTM or SHTML so Apache knows to parse it.

    Now, with PHP, a scripting language that has so much power and flexibility, why can't I get the sucker to include the same thing? I've tried this:<pre><?php
    include 'somefile.htm';
    ?> </pre>

    and I get nada. Zero. Nothing in the server's error log, because it's not an Apache error. <img src=/S/doh.gif border=0 alt=doh width=15 height=15>

    What am I missing? The back end is Redhat 6.2, more details if ya need it. I know there's a way but I am admittedly a PHP newbie!!
    -Mark

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Server-Side includes with PHP

    Mark,

    That's the correct syntax for includes in PHP.

    What version of PHP are you using?

    I hope i don't sound too much like an a**, but are you sue the file name is correct?

    Remeber in Linux file name are case sensitive. somefile.htm is different from SomeFile.htm is different from somefile.HTM

    Another thing to check is, how paths are handles. IIRC, you can set PHP/Apache to use relative paths or absolute paths based on the web root.

    One final thing to try is:

    include '.somefile.htm';

    Just a few off the top of my head ideas.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Server-Side includes with PHP

    Bryan - thanks for the thorough followup. PHP version at my host is 4.1. And rest assured, you didn't sound like an a** to me. The file name is correct, and case is also correct. I wasn't sure of the syntax. But I did look further, and here's what's confusing me.

    I am using a (hacked) version of Advanced Guestbook, and in the config.inc.php file there is the following line:
    <pre>$GB_PG["base_url"] = "http://www.broge.com/";</pre>

    The guestbook is installed in the guestbook directory off of the webserver root (that is, the publicly available section, public_html). However, the base URL seems to actually be www.broge.com/guestbook/. My ultimate goal is to use a relative path as the base URL. The host supports both.

    I will have to dig deeper into the documentation to find the pathing for the server.
    -Mark

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Server-Side includes with PHP

    Mark,

    Here is one thing I used when trying to debug PAths with PHP.

    Try and put in a non-existant image. Load the page and the right-click on the missing image and look at the path it it trying to use.

    That has helped me figure out paths before.

    Now I have just looked at the config.inc.php from the advanced Guestbook and noticed down at the bottom there is and series of If Then's

    If you leave $GB_PG<!t>["base_url"]<!/t> = "" then it will be assigned the value of the current directory.

    Maybe try that and see if it helps.

    Although, from what I can see (after a quick look) for the guestbook, it looks like the path should be: http://www.broge.com/guestbook/, since that's where the files are.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •