views:

203

answers:

2

first of all thanks for those who replied with this question,

now i am working on the vise versa of calling aspx in php

i hope you can help me.

this 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.

thank u

+4  A: 

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");
Paul Dixon
A: 

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.

Magnus Nordlander
Though you make a good point, you're assuming the output of Default.aspx is untrusted. If this is the case, then even using file_get_contents is a bad idea - a javascript based exploit can be delivered to the client.
Paul Dixon
That's a good point too. It would certainly be prudent to sanitize the fetched response. All I'm saying is that running the code through an eval() is both unnecessary and adds another attack vector.At any rate, it just goes further to show that this whole proposition is just a bad idea.
Magnus Nordlander
thsts a cool answer, its working fine with the controls and label in the aspx but i need to display an image in .php from .aspx and its not displaying well :(
ok just figured out the problem i changed the urlimage from asp :)thanks!