search
HomeBackend DevelopmentPHP TutorialApache服务器怎样设置,可以隐藏html源代码内容?

http://docs.php.net/manual/zh/intro-whatis.php

甚至可以将 web 服务器设置成让 PHP 来处理 所有的 HTML 文件,这么一来, 用户就无法得知服务端到底做了什么。 

问题:
1.

<html><head></head><body><h1 id="HTML">HTML</h1><?php   echo "PHP";?></body></html>


上面代码。
浏览器可以查看到html源代码。但是,只可以看到php源代码的结果!

如果,不想让用户知道html源代码的内容。
Apache服务器,怎样设置?
PHP官方手册(中文),哪有说明?


回复讨论(解决方案)

不让用户知道html的内容,那你准备让用户的浏览器知道不?

不让用户知道html的内容,那你准备让用户的浏览器知道不?

“甚至可以将 web 服务器设置成让 PHP 来处理所有的 HTML 文件,这么一来,用户就无法得知服务端到底做了什么。 ”

这句话是什么意思?

<?phpecho 'PHP';?>


新手路过


不让用户知道html的内容,那你准备让用户的浏览器知道不?

“甚至可以将 web 服务器设置成让 PHP 来处理所有的 HTML 文件,这么一来,用户就无法得知服务端到底做了什么。 ”

这句话是什么意思? 用户端看到的本来就是服务器端解释过都代码,也就是html啊。你以为用户都知道服务器做了什么了?比如说你登录了,用户会知道你会一直保存他的登陆信息?

更改:
1.

//a.html<html><head></head><body><h1 id="HTML">HTML</h1><?php   echo "PHP";?></body></html>

后缀是: .html。
Apache服务器,不会解析PHP源代码。
并且,浏览器也会查看到PHP源代码。
对否?

2.
//a.php<html><head></head><body><h1 id="HTML">HTML</h1><?php   echo "PHP";?></body></html>

后缀是: .php。
Apache服务器,会解析PHP源代码。
并且,浏览器也查看不到PHP源代码。
对否?

3.默认的情况下,Apache服务器只会解析后缀是:.php 的文件。对否?

4.怎样更改Apache服务器配置。使Apache服务器解析后缀是:.html 的文件?
   PHP官方手册(中文)哪有说明?

这句话的意思就是说,用户不用知道服务器做了什么,比如说你注册一个网站的帐户,其实你不用知道你提交了表单了之后,服务器做出了什么,服务器给你的只是一个反馈信息:注册成功或者是失败,其实不用服务器反馈,也可以有这样的效果,不知道明白了没有。

网页设计:
1.如果,文件代码全部是html代码。后缀是:html 最好。
   这样,Apache服务器不会作解析,直接返回客服端浏览器。

2.如果,文件代码是html,php两者混合,或全部是php代码。后缀是:php 最好。
    这样,Apache服务器会解析PHP代码,返回PHP结果给浏览器。

这样设置文件的后缀,后减轻Apache服务器的负担。对否? 

没有内容 浏览器解析什么?

3.默认的情况下,Apache服务器只会解析后缀是:.php 的文件。对否?

你的意思是,即使是类似:1.html这样的访问URI,在客户端即使用右键选择“查看源文件”,也看不到最后浏览器渲染的源代码?如果是这样,那么一般是在客户端进行设置,比如最简单的屏蔽右键啊什么的。

4.怎样更改Apache服务器配置。使Apache服务器解析后缀是:.html 的文件?
   PHP官方手册(中文)哪有说明?

这里牵涉到的问题比较复杂。

简单的说html文件不用解析,如何渲染是浏览器的事情。如果你要让html文件象php文件一样被解析,而且是按照php语法解析,那么要牵涉到MIME的更改。个人强烈不建议如此做。

你最后的帖子中提到的,我不知道你在想什么……

Apache会解析php代码,并交由PHP5的Apache Module去解析。一般情形下,会从PHP5解析模块那里得到一些结果,然后整个文件会作为html格式传送到浏览器。就是如此。

如果你直接改后缀,php代码将不会被解析,需要的结果都无法得到,就谈不上效率和负担了;

如果真的将html文件的MIME改到PHP应用,那么即使你的html是纯html,也必须经由php去解析一遍然后原样返回,效率反而会低。

总之,我不知道你在想什么。希望我的回答对你有帮助。

最后我要问的是,你的PHP水平如何?怎么会问怎么古怪的问题?如果是个新手,先别问这么牛角尖的问题好吗?

补充说一句,看文档呢,如果自己的英文还过得去,就看原版吧……(如果是我翻译的,那还可以)。

You can even configure your web server to process all your HTML files with PHP, and then there's really no way that users can tell what you have up your sleeve.

这里说的配置,就是我说的MIME配置,我强烈不建议用。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor