Can I hide PHP extension in HTML source code

好久不见. 提交于 2019-12-08 15:26:23

问题


I know that we can hide PHP extensions on URL bar. Can we hide PHP extensions when the user view source code? For example, in the index.php page (on url bar it is abc.com/index) And I view the source code, the .php extension is still there (in <a> tags). Can I hide it?


回答1:


If you already have configured your web server to interpret any chosen extension like ".do" as a php script instead of extension ".php", then all your links must use this chosen extension.

So it is not that you "can", it is you "must" use ".do" in your HTML pages.




回答2:


If you configured your server (Apache/Nginx) to work with example.com/ and (lets say an about.php) example.com/about, the links would work.

Apache htaccess example config:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [NC,L]

Thought this is just for php extensions. Though this will only help with links, lets say you are requiring a file you'll still need extensions though that wouldn't show up in element inspector/source code from browser.

<a href="./">Home</a>
<a href="./about">About</a>



回答3:


The PHP code is not visible on Server side, when you click "View Page Source", however if you submit your URL for optimisation/analystics/SEM companies (bing or google or any other such company), they can get the complete PHP server code. So, it's not foolproof. Even the webpage that you installed on webhost, the PHP code can easily be viewed by the webhost employees itself. So, it's not safe (if your PHP code is critical for you).

To hide your code, you can write your main functionality in Java and port your compiled Java code to the webserver. This way, nobody can decode your code and yet you are able to achieve what you want to do.



来源:https://stackoverflow.com/questions/47185455/can-i-hide-php-extension-in-html-source-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!