Developing a Dynamic Web site select PHP, ASP, or ASP.

Source: Internet
Author: User
Tags php example hosting web hosting
This is a frequently asked question, and it is easy to bring people into contention about Linux or the misguided windows. The controversy in fact reflects how difficult it is to conduct parallel analysis of competing web development technologies, and this difficulty is greatly increased by developers ' differing views on any comparable operating system.

So instead of continuing to engage in such debates, we might as well look at the advantages that each technology has for a particular web development and the operating environment. Although ASP and PHP are much more similar than any of them, we will discuss ASP. The reason is that developers often confuse it with ASP, and with Microsoft's efforts, ASP will definitely replace ASP in the future.

Basic theory--Features overview
php--Hypertext Preprocessor (hypertext Pre-processor)
PHP is an open source server-side scripting language that is syntactically similar to the C language. Although originally designed for use with the Linux-based Apache Web server system, PHP has now been ported to any operating system and is compatible with any standard Web server software. The three main advantages of PHP can also be derived from this. First, it's a cross-platform technology, so PHP applications can be easily ported-and of course it depends on additional components such as vendor-specific databases that need to be integrated. This portability also brings the advantage that most web hosting providers will support PHP, so it will be convenient to change the host as needed.

2nd, because PHP has a lot in common with the C programming language, PHP is very easy to use for developers who are familiar with the syntax, which is also used in Java, JavaScript, and Perl. Third, because it is an open source product, PHP will continue to develop rapidly, and more importantly, the relevant vulnerability patches will be regularly implanted into the core library free of charge.

In addition, PHP has shown a more attractive appeal to developers in some specific programming needs. First, PHP has built-in libraries to support direct creation and related operations for images and PDF documents. This means that when an application invokes a dynamically created menu image that contains anti-aliased type text, or if it is necessary to export the Acrobat format page, PHP will be the ideal technique for solving such problems. Although these features can theoretically be obtained through other competing technologies with PHP, other technologies often require the installation of third-party custom components to be implemented.

Another point makes PHP the best choice for writing server scripts is the good performance of PHP when dealing with issues such as connecting Mysol or Postgres databases. Although access to Mysol or Postgres databases can be implemented through ASP technology with ODBC connections, this often requires additional configuration by the system administrator. Fortunately, this limitation was corrected in ASP. Data can be provided via MySQL when a direct database connection similar to MS SQL Server needs to be established.

asp--Dynamic Services page (Active Server pages)
Microsoft introduces ASP to Windows NT Server 4 and uses it as the default platform for dynamic Web applications under the IIS Web server. Because it uses VBScript (a branch of the Visual Basic language), ASP is immediately sought after by developers familiar with Microsoft Ide--visual Studio programming. With the development of scripting language, the researchers have not introduced too many functions to the ASP to join the ranks of technology competition. As a result, functions such as operations that can be seen in PHP are not integrated into the ASP. But developers can still write (or install) third-party COM objects in the form of DLL files to do similar work. In this way, you can write code to accomplish any action, as the server itself allows. The flaw, of course, is that this will lead to the need for these service developers to interact with desktop systems-a feature that is not required for web developers.

The advantage of ASP is that Microsoft servers are almost ubiquitous in an enterprise environment. In addition, MS SQL Server also has a broad market and is well-supported by ASP (which is not surprising). Although virtually any data source can be compatible with ODBC, SQL Server and file DSN Access can be implemented at the code level.

asp
The controversy over whether to choose ASP or PHP is becoming increasingly redundant with the rise of. Net. Indeed, the debate over the past few years will end with the announcement of whether to choose Java or. NET technology (or both). The only connection between ASP and ASP is that both use VBScript. and alone. NET, it can use VBScript and some other 20 languages.

For ASP and PHP, the reason to consider ASP. NET as another language is that it runs on a completely different architecture. The former is the translation scripting language, while. NET is the compiled framework. This means that the first time the Web page will run at a significantly higher speed. At the same time, the source code is more secure and more robust. In addition, ASP. NET brings new ideas to web programming-the idea of "code-behind pages". According to Code-behind thought, each HTML page is driven by its own compiled programmatic instructions. As a result, html--or the presentation layer-is largely out of the business logic of the application. Although this separation can also be achieved through PHP and ASP, this is not the same as the main part of your own technology as ASP.

Asp. NET also benefits from its complete integration of various support for XML and Web services. A very wide range of security and password system libraries are available for. NET, which is especially useful for financial institutions and enterprise data applications. In the case of defects, even experienced developers will find it. NET may confuse itself. Regardless of how familiar the developer is with the programming language used, a significant increase in the difficulty of the program paradigm may be a major hurdle for web developers to integrate with ASP. Hosting is also a problem for ASP. asp or PHP does not have the same host provider's broad support to compete at the same level.

Practice-language comparison
Variable declaration


In VBScript (both ASP and ASP. NET use VBScript), it is not necessarily declared before using variables, although technical documentation is generally recommended. Using the Option Explicit declaration, a developer can force a variable declaration through a program. In PHP, variables can be declared, although there is no way to force developers to do so. Indeed, variables are declared automatically before they are used. The advantage of PHP variables is that variables can be set as references to other variables (references), whereas in VBScript variables are defined only by value.

<% ' VBScript exampleoption explicitmyvar = 1myOtherVar = Myvarmyvar = 2 ' myresult would be 3myResult = MyVar + Myotherv Ar%>
<?//PHP example$myvar = 1; ' Use the ampersand-make a reference$myothervar = & $myVar; $myVar = 2;//$myResult'll be 4$myresult = $myVar + $myOt Hervar;? >


Variable Collection
The use of forms and query string variables in PHP and ASP is very similar. There are many ways to access the form and the collection of query string variables, such as by name or as an array. There are many differences in ASP. NET, especially for form fields. Unlike blindly looking for submitted form variables, Code-behind can be familiar with every form field in an HTML page, and the values of those form fields can be checked against any known event's execution as a condition. One of the events is "postback", which is triggered when the form is submitted by the user. Other events can be client-side programs and can be triggered by JavaScript. In ASP. NET, there is no difference in nature.


<% ' ASP examplemyformval = Request.Form ("Myinputfield") Myqsval = Request.QueryString ("Myqsitem") MyVal = Request.item ("Myformorqsitem")%>
<?//PHP 4.1+ example$myformval = $_post[' Myinputfield '); $myQSval = $_request[' Myqsitem ']; PHP example$myformval = $HTTP _post_vars[' Myinputfield ']; If register_globals = On$myval = $myFormOrQSitem;? >
<!--ASP. Example-->


String connection (concatenation)
PHP seems to pay enough attention to this issue, allowing variables to be inserted into a string without regard to the usual concatenation (concatenation) problem. Asp. NET makes the whole process more cumbersome and requires the use of its StringBuilder class, but this makes it run much faster.

<?//PHP Example$link = mysql_connect ("host", "User", "password") or Die ("mysql_error ())", mysql_select_db ("Database" ) or Die ("Could not select Database"), $query = "SELECT * from Table", $result = mysql_query ($query) or Die (Mysql_error ()); while ($line = Mysql_fetch_array ($result, Mysql_assoc)) {foreach ($line as $col _value) {//do something}}?>

Connecting to a database
For the connection problem of database, each kind of technology has shown its own outstanding normative. First, a connection to the database is established for each case. For PHP, select the database after Setup (for ASP and ASP. NET will be completed during the connection phase). A query is then created and transmitted to the database, which may or may not produce a return record.


Because ASP. NET is more object-oriented and supports complex error handling (handling), ASP. NET may need to write more code for simple tasks, whether it's PHP or ASP. But in terms of advantages, ASP. NET the code required to complete the display of data functions is significantly less than PHP and asp--, especially if the built-in DataGrid control is used to automatically create HTML output.

<% ' ASP exampleset objconn = Server.CreateObject ("ADODB. Connection ") objConn.Open" Driver={sql Server}; Server=myservername; "& _" Database=mydatabasename; uid=; pwd= "Const strSQL =" SELECT * from Table "Set objRS = Server.CreateObject (" ADODB. Recordset ") Objrs.openstrsql, Objconndo while not objrs.eof ' do somethingobjrs.movenextloop%>

' ASP. Example

<%@ Import namespace= "System.Data"%>

<%@ Import namespace= "System.Data.SqlClient"%>


Conclusion

Choosing ASP, PHP, or ASP will ultimately depend on the needs of your application and the system environment in which you run your program. Developers ' familiarity with similar programming languages or paradigms can also be a factor of choice. Remember that there is no perfect method and individual facts to show which technology is the best choice. For example, using ASP. To create a single-page form mail application for a Windows server might seem overkill, but it's an excellent application environment for ASPs. If a site needs to be connected to a MySQL database on a Linux Apache server, using ASP or ASP. If the user's personal requirements can be carefully considered in advance, then the process of selecting the developers in these competing technologies is half done.

The above is the development of Dynamic Web site selection of PHP, ASP or ASP, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.