PHP and ASP in the same page

I’m converting a small business application from ASP/Access to PHP/MySQL. It would be very useful if I could, during the process of conversion, run the odd page with bits of both ASP server-side code and PHP. I presume this should be possible?

If so, please:-

  1. What else do I need to do on the page apart from putting the PHP bits in <?php …?> delimiters? (The ASP code is already in <% … %>)
  2. The development machine runs MS PWS, the eventual host target the latest IIS.
  3. Does it matter whether I use .PHP or a .ASP page suffix?

All advice gratefully received. Thanks. - Mike -

This will never work I’m afraid. It’s down to the way things are processed.

Web servers look at the extension on a file and use that to determine if the page is a script which needs executing or not, and if it is, where to route the script to to be executed. Eg:

.html = no server scripting, just push page to client browser for rendering
.asp = scripting mapped to asp.dll (in IIS)
.php = scripting mapped to php.exe (I think!)
etc.

The web server uses the file extension to know which application will be required to execute the script. A .asp file is handled by the MS driver, asp.dll, which obviously has no idea what to do with PHP code! A .php file goes via php.exe which naturally has no idea what to do with an ASP file! So either way, whether it’s a PHP file with ASP code in or vice versa, it is doomed to 500 error on you. The two are inherrently incompatible and you cannot mix them because of the way your web server handles scripting.

And because the ASP engine is not open source, it’s unlikely even the most enterprising individual has ever bothered to create a scripting engine that can parse both PHP and ASP, although I guess it would be technically possible to write one.

G

Very clear explanation, even if not what I wanted to hear. I think I can avoid the need now anyway, but thanks, I’ve learnt something!

No probs. Sorry it wasn’t good news. :slight_smile:

Edit:

FYI, you can view the mappings by opening the PWS/IIS MMC panel, right clicking on the website, going to Properties, clicking the ‘Home Directory’ tab and clicking the ‘Configuration’ button. Here you can see an editable list of what file extensions map to what applications. :slight_smile:

Why do you need to have them in the same page?

would an ASP parser ignore code in PHP tags? if so, then (no idea if this would work) set ASP to be parsed by both the ASP.dll and php.exe!? cant that be done? and then the asp.dll would ignore the php code?

A total stab in the dark about whether it would work though!

No - it would try and parse the code and fail, unfortunately…

what you can try is:



include('http://www.example.com/myAspScript.asp');


so that your ASP code is parsed first, and then its result is included into PHP.

Nice trick! :smiley: (If it works…)

Thanks to all for their contributions. As stated above, I now hope to avoid the need, but if push comes to shove I will indeed try Berislav’s idea!

Cheers.

Experiments suggest that I cannot redirect from a PHP page to an ASP page. :bawling:

I’ve tried to redirect using both the
header("Location : target.asp’) PHP technique and the
<meta http-equiv=“refresh” content=“0;url=target.asp”> HTML technique
without success. The target.asp page in each test was plain old HTML, nothing at all in it that was ASP-specific.

If, however, you rename the same target file as either .HTM or .PHP, the redirect is successful.

Testing was done on MS PWS, an installation which is well-behaved and stable for both PHP and ASP pages.

I can’t get my head round why such a redirect might fail - perhaps someone more expert than I could explain (please)?

Thanks.

BTW: also, as far as I can establish, BerislavLopac’s cunning plan earlier in the thread for a way to mix ASP and PHP on the same page is (unfortunately) NBG.

Forget about this conversion and hold on to your default ASP page or you convert this to PHP adn make it PHP throughout because I am some kind of sure that this will never work. But if it does, that’s your luck.

Chris xKizer

can i somehow include a php page into a asp page ?

I have a navigation menu designed with php what retrieves the directory entries of a product database … i need to include this php page on top of many asp pages … HOW ?

Any help is very much appreciated

Based on my experience in trying to get this sort of thing to work (even with the advice of the good folk here) I now think that you’re wasting your time.

What I was able to do was to mix PHP pages in amongst ASP pages to achieve my objective, but I totally failed to actualy mix the two on as single page/script.

Could you perhaps rewrite your PHP based menu in ASP? I ended up with a system where I talk to Access databases from ASP and from PHP, and MySQL databases from ASP and PHP. One complete mishmash, but it seems to work, and in my case it’s only a temporary expedient.

Whichever way you decide to approach it, all the best!

That’s strange – I’m pretty sure it worked for me. (can’t test it right now).

Did you enter the whole URL, as in my example (including http.// and complete path)? Relative links might not work, but complete ones should…