SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Edinburgh, UK
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php/html Why cant I use

    Hi all,

    Slightly confused, I gather PHP can be inserted into an existing .html page.
    Tryed to insert PHP into a .html document in my localhost/htdocs folder but for some reason it will not work. The view source option in my web page which works fine within localhost shows the PHP coding and should'nt and the PHP section wont function.
    What am I missing.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Edinburgh, UK
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do all files have to be named .php to work ?, just renamed the .html file to .php and it works in localhost so therefore my question is do all files have to be named with .php, and will not work with php code within a .html document.

  3. #3
    SitePoint Addict bbparis's Avatar
    Join Date
    Aug 2008
    Posts
    323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by serecarteren View Post
    Do all files have to be named .php to work ?, just renamed the .html file to .php and it works in localhost so therefore my question is do all files have to be named with .php, and will not work with php code within a .html document.
    Hello,

    yes, as I know, you can't integrate php codes in HTML page, I did that before and the only solution I had, is to integrate the code in php pages only, this is mean .php as you said.

    I think I understand why you are asking this question, you want to have the header in one file, and integrate it in all the other pages with php code ( example : include("header.php"); ) and than, when you change the header page, other pages will be updated automatically, non ?

    Anyway check the following link, I hope it will be helpful for your :

    http://www.kirupa.com/web/phphtml.htm

    Best regards

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2008
    Location
    Gloucestershire, UK
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want the server to parse PHP in .html pages the easiest way is to create a .htaccess file with the following code:

    Code:
    AddType application/x-httpd-php .html .htm
    Cheers,

    Jon

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Edinburgh, UK
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks v much for info, am i right in thinking this goes into Apache




    AddType application/x-httpd-php .html .htm

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2008
    Location
    Gloucestershire, UK
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just create a file in a text editor/IDE and save it as .htaccess (just the extension without a file name) and then simply upoad it to your web directory (htdocs etc) where the html files are kept.

    Cheers,

    Jon

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Edinburgh, UK
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The .htaccess don't work, but typing your code snippet into apache\conf\httpd.conf works perfectly.

    Thanks guys

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,832
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by jonpugh114 View Post
    just the extension without a file name
    That's a filename without an extension, not an extension without a filename. Linux uses a leading dot to indicate a hidden file.

    It has to be enabled before the .htaccess will be recognised and its only use is for overriding the content of the httpd.conf for a specific directory.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just remember though - now every HTML document will be treated this way. (Parsed for PHP) Not bad for really small sites - but it can become a burden for larger sites. Cheers!


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
  •