简体   繁体   English

如何使用javascript读取php文件的内容

[英]how to read the contents of a php file using javascript

So let's say I have a form tag like so. 假设我有一个这样的form标签。 And I want to print the contents of the file to screen using JavaScript. 我想使用JavaScript将文件的内容打印到屏幕上。 How do I go about doing that? 我该怎么做?

<form action="/missions/basic/3/index.php" method="post">
    <input type="hidden" name="file" value="file.php" />
    <input type="password" name="password" />
    <br />
    <br />
    <input type="submit" value="submit" />
</form>

What I want is to use the alert() function to show the contents of file.php, even though the contents are hidden. 我想要的是使用alert()函数显示file.php的内容,即使该内容是隐藏的。

What I want is to use the alert() function to show the contents of file.php, even though the contents are hidden. 我想要的是使用alert()函数显示file.php的内容,即使该内容是隐藏的。

You just can't . 不能 Don't waste your time :) 不要浪费你的时间:)

If your web server is configured correctly it will never output PHP code even if you could request that from JavaScript. 如果您的Web服务器配置正确,则即使您可以从JavaScript请求它也不会输出PHP代码。

You can grab and show the output of a PHP file on the client but not its source code like that, unless there is a mess up or it is by design. 您可以在客户端上捕获并显示PHP文件的输出 ,但不能像这样显示其源代码 ,除非出现混乱或设计使然。

PHP is server side programming. PHP是服务器端编程。 When you run, it'll return the output of server coding not the server code 运行时,它将返回服务器代码输出而不是服务器代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM