开发者

What about calling aspx in php?

开发者 https://www.devze.com 2022-12-10 17:51 出处:网络
Here is my code <html> <body> <?php include(\"Default.aspx\"); ?> </body> </html>

Here is my code

<html>
<body>

<?php
include("Default.aspx");
?>

</body>
</html>

but it keeps giving me the output of

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"开发者_开发百科 %> <% Response.Write("Hello world!"); %>

I just need to run the Hello World on the site.


If you want the output of the aspx file, you will need to request it via a web server which can understand aspx files rather than the file system, e.g.

include("http://example.com/Default.aspx");

Your PHP installation must have URL fopen wrappers enabled for this to work.

As Magnus Nordlander notes in another answer, you should only use include if you expect to find php code in the file. If you don't, you could simply use readfile to output the data verbatim:

readfile("http://example.com/Default.aspx");


You seem to be going about this in a very wrong way.

What include() (and require(), for that matter) does is that it parses the specified file with the PHP interpreter. If your aspx-code for some reason generates PHP-code, which is supposed to be parsed by the PHP interpreter, then the way Paul Dixon suggests would be the right way of going about this. However, I would strongly advice against doing this.

For one thing, it's a huge security disaster waiting to happen. It's also incredibly bad architecturally speaking.

If you want to include HTML markup etc. generated using aspx, what you should do is to use

echo file_get_contents("http://www.example.com/Default.aspx");

This way, any PHP code in the output remains unparsed, thus avoiding the aforementioned security disaster. However, if you're able to do without mixing languages like this, that's probably going to be a much better solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消