PHP vs ASP.NET Part 1

Revelations I've Had While Trying To Learn ASP.NET

Thursday, January 27, 2005 by Zoomba | Discussion: Websites

Alright, at work I've been told I have to build a web tool that takes a 40 question survey, analyzes the answers given, then based on the answers generate custom content from a large stack of documents. Fair enough. The catch is I have to do it in ASP.NET, and not PHP because ASP.NET is supported by IT whereas PHP is not (despite the fact that IT runs serveral PHPNuke sites, which obviously relies on PHP).

So, I've been trying to learn ASP.NET for the purpose of building this tool. In the short time I've been at this, I've been frustrated by the needless layers of complexity Microsoft introduces into the process of building a dynamic web page. This is the first part in what will likely be a multipart series of articles in which I compare and contrast PHP and ASP.NET. This will be the foundation for a later report I've been asked to write for the head of the Architecture Practice here to show the relative merits of adding PHP to the supported list.

I admit I'm biased here by the fact that I am familiar with one, but not the other. However, I'm going to try and limit my points to items where there is a clear difference between the two... Each of these articles will compare and contrast the two on a specific problem I'm encountering.

1.) How Much Do You Need To Know?
Ok, lets say you want to create the most basic dynamic page. All you want to do is have a form with a text field that you fill in with whatever text you like, and when you click submit, it loads a page that displays that text and nothing more. No databases, nothing complicated. How much do you need to know to do that in either language? Well, let's take a look...

PHP
Languages Needed: PHP, HTML
Solution method: The form page is simple HTML form, all it does is POST to the target php page to display the text. The target PHP page grabs the posted field, assigns it to a variable and prints it to the screen. Lines of code in PHP... 2.

ASP.NET
Langauges Needed: ASP.NET tags, HTML, VB.NET/C#/Whatever your desired .NET language is... so in essence, 3 languages
Solution method: Well, in ASP.NET, you don't POST to other pages, you POST back to the same form, write a button click event that processes the information and assigns it to a variable. Then either redirect everything to a second page, or load the variable as a label somewhere on the original page. Lines of code? Too damn many. I still haven't figured this out properly. I know for damn sure it's a lot more than 2 lines though.
mick_k
Reply #1 Thursday, January 27, 2005 11:39 AM
It's actually just one line of code in .net

Here is the first page just regular html.










WebForm.aspx:






WebForm






mick_k
Reply #2 Thursday, January 27, 2005 11:46 AM
oops, can't post the html code. Try again. Just replace the number sign with the less then and greater then signs

test.htm:
#html#
#body#
#form id="boo" name="booo" action="WebForm.aspx"#
#INPUT id="Text1" type="text" name="Text1"# #INPUT id="Submit1" type="submit" value="Submit" name="Submit1"#
#/form#
#/body#
#/html#

WebForm.aspx:
#%@ Page language="c#"%#
#!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" #

#html#
#body#
#%=Request["Text1"]%#
#/body#
#/html#
Zoomba
Reply #3 Thursday, January 27, 2005 11:58 AM
BIG cookie for you! I couldn't find that anywhere on the ASP.NET sites I found and it wasn't in my huge ASP.NET book. Thank you for saving me from the past few hours of frustration!!
47songs
Reply #4 Friday, January 28, 2005 9:40 PM
Excuse me?
Weaksid
Reply #5 Saturday, January 29, 2005 7:34 PM
Here is something, if you plan on using databases. ASP you have to pay for each and every connection to the database Per user. In PHP, it's absolutely free! Microsoft just wants you to pay for a liscense for each connect on top of the software cost. Just think, one person alone can probably suck up almost 10 connections or more depending on how your server is setup. My suggestion is go with PHP if you want to learn something.
SteveA5206
Reply #6 Saturday, January 29, 2005 11:11 PM
The .Net Framework creates a user called ASPNET...set up your web app/database to utilize this user. You only need ONE user to make your database available on the web and you DON'T have to pay for it.

P.S. Put the connection to the database in the web.config file or leverage 'PostBack' and you only need ONE connection.
Weaksid
Reply #7 Sunday, January 30, 2005 12:27 AM
O' so there is a diffrence between ASP and ASPNET. Because when I had a class on ASP, I was told that you had to pay for a liscense for each connection to the database.
dan.wright
Reply #8 Sunday, January 30, 2005 12:46 AM
That all depends on which backend database you are using and what type of licensing package purchase. For SQL Server, you can get licensing on a "Per Server/Processor" basis, or "Per Connection". All depends on what kinds of money a company wants to shell out. I would assume Oracle has a similar licensing plan.
SteveA5206
Reply #9 Sunday, January 30, 2005 11:16 AM
I always considered ASP.NET to be the replacement for ASP. They are similar in some respects and you can still code classic ASP (as well as javascript) within your app but why would you want to? There are an abundance of very cool .Net controls out there or you can even write your own. In fact, I am in the process of rewriting all of our company's telnet applications (which access datasets on our mainframe - old TN3270 apps) in ASP.Net with a SQL backend. 5 years ago I would not even have considered such an undertaking with the tools available at the time (such as ASP). Total development/conversion time about 18 months which includes a few months of school work.
Needmorezelda
Reply #10 Sunday, January 30, 2005 5:38 PM
I know and love PHP, but have no experience in ASP, so I can't make a fair comparison between the two. But something confused me in the article. Why two lines in the PHP page? Wouldn't it simply be:

<?php echo $_POST['form_element_name'] ?>

Only one line, right?
Zoomba
Reply #11 Sunday, January 30, 2005 5:53 PM
As far as doing it in two lines, because I'm rarely just redisplaying a passed variable, I usually assign it to a new variable from the POST data and then manipulate/display that information. Makes it a bit more readable too IMO.
mrbiotech
Reply #12 Sunday, January 30, 2005 6:53 PM
Can't wait to see further articles on this topic- unexpected side-effect is collaboration and sharing of techniques. Looks like everyone will benefit.
joeKnowledge
Reply #13 Sunday, January 30, 2005 7:53 PM
I agree that this should be interesting.

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01