1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Cannot Embed PHP in HTML

Discussion in 'Apache' started by James_Brown, May 2, 2011.

  1. #1
    I have:
    Apache 2.2.1
    Php 5.3.6
    MySQL 5.5.10
    All up and running fine. I can server HTML and PHP pages just as advertisedized. What I can not do is embed PHP in the HTML page. I have tried all the different types of escape code:
    <? ... ?>
    <?php ... ?>
    <script language="php" > ... <?script>
    <% ... %>
    None of them have the slightest effect. I think I must have Apache configured wrong - but where?
    SEMrush
     
    James_Brown, May 2, 2011 IP
    SEMrush
  2. MartinPrestovic

    MartinPrestovic Peon

    Messages:
    213
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi James,

    If you want PHP to be parsed inside a HTML file then you need to tell Apache to treat the .html / .htm extension as a PHP file. Otherwise it is just treated as plain HTML and will output your code as plain text.

    You can do this by editing the AddType in your httpd.conf file. In that file there should be a line like this:

    AddType application/x-httpd-php .php
    Code (markup):
    Simply change that to:

    AddType application/x-httpd-php .php .html .htm
    Code (markup):
    Restart Apache and then your HTML files will parse your PHP code.
     
    MartinPrestovic, May 6, 2011 IP
  3. mickapoo

    mickapoo Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    I'm having a similar issue. While I can view includes with .shtml extensions, if I try to use PHP includes, they don't get parsed by the browser. I know the syntax is right because the includes do come up correctly when I upload the website to the hosting server.

    This is what I currently have in the httpd.conf file:

    AddType text/html .shtml .php
    AddOutputFilter INCLUDES .shtml .php

    I am running Apache 2.2 and Windows XP.

    Thank you for your help!
     
    Last edited: May 9, 2011
    mickapoo, May 9, 2011 IP
  4. MartinPrestovic

    MartinPrestovic Peon

    Messages:
    213
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    First of all make sure you have PHP installed. Just having Apache installed won't give you PHP on your local machine.

    SHTML Includes and PHP Includes are completely different. Your code in the .shtml files is probably fine, they work when you upload them to the hosting company because the hosting company has Apache httpd.conf file configured correctly.

    The first line, your telling Apache to parse .shtml and .php extensions as text/html and in the second line your telling Apache to parse .shtml and .php for SHTML Includes. PHP includes will not be affected by this setting because the files are initially being parsed as text/html.

    You need to tell Apache to parse .shtml extensions as though they were PHP. I am assuming based on your post that all of your files are named index.shtml file1.shtml, file2.shtml and that you are not using the .php extension at all. Therefore the following should work for your situation:

    
    AddType application/x-httpd-php .shtml 
    AddOutputFilter INCLUDES .shtml
    
    Code (markup):
    If you are using files which end with the .php extension, e.g. myfile1.php, includea.php, includeb.php then change the first line to:

    
    AddType application/x-httpd-php .shtml .php
    
    Code (markup):
    Note that I have not tested this as I have no use for SHTML and haven`t used it for years, but I am pretty sure it's correct.
     
    MartinPrestovic, May 9, 2011 IP
  5. Matix

    Matix Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    first of all I assume you are using a *Nix based system run
    httpd -M
    Code (markup):
    and check if php5_module is loaded

    If not install it.
     
    Matix, May 14, 2011 IP