zoukankan      html  css  js  c++  java
  • 从一个.html文件上执行php文件

        How can I execute PHP code on my existing myfile.html page?: When a web page is accessed, the server checks the extension to know how to handle the page. Generally speaking if it sees a .htm or .html file, it sends it right to the browser because it doesn't have anything to process on the server. If it sees a .php extension (or .shtml, or .asp, etc), it knows that it needs to execute the appropriate code before passing it along to the browser.
        Here is the problem: You find the perfect script, and you want to run it on your site, but you need to included PHP on your page for it to work. You could just rename your pages to yourpage.php instead of yourpage.html, but you already have incoming links or search engine ranking so you don't want to change the file name. What can you do?

        First let me preface this by saying that if you are creating a new file anyway, you may as well use .php. This is to help people who have existing .html pages they need to execute PHP on.

        The way to execute PHP on a .html page is to modify your .htaccess file. This file may be hidden, so depending upon your FTP program you may have to modify some settings to see it. Then you just need to add this line for .html:

        AddType application/x-httpd-php .htmlOr for .htm
        AddType application/x-httpd-php .htmIf you only plan on including the PHP on one page, it is better to setup this way:
    <Files yourpage.html> AddType application/x-httpd-php .html </Files>This code will only make the PHP executable on the yourpage.html file, and not on all of your html pages.
    Things to watch out for:

        If you have an existing .htaccess file, add this to it, do not overwrite it or other settings may stop working! Always be very careful with your .htaccess file and ask your host if you need help
        Anything in your .html files that starts with <? will now be executed as PHP, so if it's in your file for some other reason (an XML tag for example) you will need to echo these lines to prevent errors. For example:
    <?php echo '<?xml version="1.0" encoding="IUTF-8"?>'; ?>


  • 相关阅读:
    Ocelot简易教程(一)之Ocelot是什么
    如何测量并报告ASP.NET Core Web API请求的响应时间
    ASP.NET Core 2.1中基于角色的授权
    Net Core平台灵活简单的日志记录框架NLog+SqlServer初体验
    Net Core平台灵活简单的日志记录框架NLog+Mysql组合初体验
    Net Core集成Exceptionless分布式日志功能以及全局异常过滤
    CentOS7 PostgreSQL安装
    Python 的 List 要印出 中文 編碼
    如何让你的Python代码更加pythonic ?
    4种格式化字符串方式的时间效率比较
  • 原文地址:https://www.cnblogs.com/see7di/p/2239918.html
Copyright © 2011-2022 走看看