Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

SOLVED PHP include in HTML File Question

Discussion in 'General Discussion' started by val98, May 21, 2018.

  1. val98

    val98 Member

    Joined:
    May 21, 2018
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    PA
    cPanel Access Level:
    Website Owner
    This question is probably really dumb, but how do I get a html file to successfully call a php file?
    I know my php file works because when I call it directly www.example.com/example.php it works, but when I put it in a html file using <? php include('example.php'); ?> it doesn't work. What am I doing wrong?
    Thanks
     
  2. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,872
    Likes Received:
    89
    Trophy Points:
    78
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Hi,

    A webserver has specific handler configured to execute specific files, like a PHP handler to use for executing .php file. PHP handler does display result of html too but the vice versa is not true. HTML coding is differnent, so when you have .html file, a webserver sees it like the same and does not execute PHP codes in it, as PHP handlers were not used for .html file to execute it.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,802
    Likes Received:
    1,895
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. val98

    val98 Member

    Joined:
    May 21, 2018
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    PA
    cPanel Access Level:
    Website Owner
  5. dalem

    dalem Well-Known Member
    PartnerNOC

    Joined:
    Oct 24, 2003
    Messages:
    2,741
    Likes Received:
    76
    Trophy Points:
    203
    Location:
    SLC
    cPanel Access Level:
    DataCenter Provider
    public_html/.htaccess

    easy way to achieve

    rename the all files to php
    then

    add

    RewriteRule ^([^.]+)\.html$ $1.php [L]

    to your .htaccess

    Now page.html will be a php page and php will run inside

    optional we add this addition to our .htaccess

    RewriteCond %{THE_REQUEST} \ /(.+)\.php
    RewriteRule ^ /%1.html [L,R=301]


    it just 301 redirects site.php pages to its html equivalent
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    cPanelMichael likes this.
  6. val98

    val98 Member

    Joined:
    May 21, 2018
    Messages:
    6
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    PA
    cPanel Access Level:
    Website Owner
    Thank you!!!!!!! It works now!!!
     
    cPanelMichael likes this.
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice