SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Location
    Brisbane
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Including data from a PHP program in a SHTML page

    I want to use a PHP program for a directory which will be part of my site. However, the program can't deal with some of my ad requirements and I want to use my own .shtml page with my headers, footers and ad column, drawing just the centre part of the page (ie the directory listings) from my pre-purchased PHP program.

    I can do this with iFrames, but I presume that this is bad for SEO (as the actual content of the iFrame is not displayed in the page source and anybody performing a search will find the iframe source, without all the headers, etc) rather than the completed page.)

    Is there a way that I can pull that PHP content over with includes or contentDocument at all?

    The PHP program does produce a friendly URL of the form...

    http://www.mysite.com/directory/Cate...irectory.html/

    However, if I try an include command with that url:

    <!--#include file="http://www.mysite.com/directory/Category/shopsdirectory.html/" -->

    I just get an error message:

    [an error occurred while processing this directive]

    Is what I'm trying to do possible and I've just got the coding wrong? Or impossible and iFrames is really the only way to do it (other than modifying the pre-purchased PHP prog enormously)

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't use an absolute URI in an SSI include statement. Try this:
    HTML Code:
    <!--#include virtual="/directory/Category/shopsdirectory.html/"-->
    (Note that I used virtual instead of file.)
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Member
    Join Date
    Aug 2006
    Location
    Brisbane
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't like that either - I get the same error.

    The page definitely exists, for example, if I do a <a href="directory/Category/shopsdirectory.html/">link</a> command, I get a link to that page working ok.

    Anything else I can try?

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there some sort of URI aliasing going on? Do you use mod_rewrite or similar to translate /directory/Category/shopsdirectory.html/ into mycomplexscript.php?foo=bar&#38;abc=def?

    Also, I noticed the trailing slash in your 'friendly' URI, which indicates that shopsdirectory.html is actually a directory, rather than an HTML document. In that case you will probably have to specify the full file name, like
    HTML Code:
    <!--#include virtual="/directory/Category/shopsdirectory.html/index.php"-->
    (Or whatever the target file name is.)
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Member
    Join Date
    Aug 2006
    Location
    Brisbane
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The program does use mod_rewrite to make the php address into a 'friendly' url. However, I want my original pages searched, rather than the bit that I'm pulling over from the php program, so I guess it doesn't matter if the url from the purchased php program is not 'friendly'

    What I've done is switched off the mod_rewrite, so that now the address of the directory page is http://www.mysite.com/directory/index.php?id=5

    I've changed by complete page ending from .shtml to .php, and if I include the following line of code...everything works beautifully.

    PHP Code:
    <?php include "http://www.mysite.com/directory/index.php?id=5";
    $id 5;
    include 
    'index.php';
    ?>
    In an ideal world, I'd be able to keep my pages with the .shtml page ending. Is there anyway of incorporating the above into a .shtml page instead of a .php page? I tried using...

    HTML Code:
    <!--#include virtual="/directory/index.php?id=5" -->
    It brings something over, but it's just rubbish that looks like this...

    ������x��V[o�0~.R���h�&E��i�v�i��:i{�v��=�4���6�A.��^Jd�s��9�9��|��� ̵�a����i��U:��v���٭��U�L)$e lrJ5�4���ҡ@�`����]At���(� ��)����$��V*�)'u�&#37;���

    Is there some coding I can use, or can't you include a php file in an shtml page?

  6. #6
    SitePoint Member
    Join Date
    Aug 2006
    Location
    Brisbane
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've played around with this for a while and have now used .htaccess to parse .shtml with php - so I can get php working in my .shtml pages.

    And I tried the following code...

    <!--#include virtual="directory/aaatest.php" --><br>
    <!--#include virtual="directory/index.php?id=5" --><br>
    <!--#include virtual="directory/index.php" --><br>

    aaatest.php is the source code from directory/index.php just cut and paste into a notepad file and saved to the server.

    The aaatest.php works fine and appears on the page. The other two just show nothing at all - no error, nothing. If I view the source code of the finished page, that coding has disappeared from my .shtml page.

    So now I'm confused as to why the top one works, but the other two don't.

    Any ideas?

  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Server-side includes are simple file inclusions. They are not HTTP requests.

    Your second example tries to include a file named index.php?id=5 in the given directory (BTW, you should use root-relative paths with virtual=; use file= for relative paths).

    The third example probably doesn't work because index.php expects an id parameter to be present in the $_GET superglobal.
    Birnam wood is come to Dunsinane

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Why not just use PHP in the first place instead of trying to get SSI to do something it is not designed to do?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    SitePoint Member
    Join Date
    Aug 2006
    Location
    Brisbane
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I probably will - it just means that I have to change all the page endings for my site to .php from .shtml, which involves code changes for a fair number of internal links. If I could have avoided that with some simple coding, that would have been great, but if a) it wouldn't work properly and b) it's bad practice, then I'll just make the switch to calling all my pages .php. Not the end of the world!

    Thanks for all your help.

  10. #10
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    use file= for relative paths
    Why? (As in why not virtual=""?)
    Simon Pieters

  11. #11
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by zcorpan View Post
    Why? (As in why not virtual=""?)
    Oh, I suppose it doesn't really matter, but I assume file= would be a bit more efficient since it doesn't have to take the document root directory into consideration.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

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