# ASP (not the snake) VS PHP

**URL:** <https://boards.straightdope.com/t/asp-not-the-snake-vs-php/394363>\
**Category:** Factual Questions\
**Created:** [March 2, 2007, 10:29pm UTC](https://boards.straightdope.com/t/asp-not-the-snake-vs-php/394363 "2007-03-02T22:29:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Epimetheus](https://avatars.discourse-cdn.com/v4/letter/e/c4cdca/32.png) [@Epimetheus](https://boards.straightdope.com/u/Epimetheus)\
**Post date:** [March 2, 2007, 10:29pm UTC](https://boards.straightdope.com/t/asp-not-the-snake-vs-php/394363/1 "2007-03-02T22:29:16Z")

</div>

My Database teacher, claims that PHP is very insecure, and most businesses use ASP because it is much more secure. Looking online, it seems there is a lot of hits with people defending ASP by saying it is AS secure as PHP, which suggests many people think it is less secure than PHP.

Without getting into opinions a la Microsoft VS Open Source, from a factual point, can ASP and PHP be equally secure, or is there something about PHP that makes it inferior from a security standpoint?

Is my teacher passing his opinions/biases onto us students? Is PHP not secure enough for web apps or am I being deceived?

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [March 2, 2007, 10:35pm UTC](https://boards.straightdope.com/t/asp-not-the-snake-vs-php/394363/2 "2007-03-02T22:35:00Z")

</div>

Your database teacher is comparing apples and oranges.

PHP is a programming language which specialized in creating web applications. (Though it can do other things.) PHP can run either in a CGI environment or as a built-in web server module. (mod\_php with Apache.)

ASP is an interface specification for sending dynamic content to Microsoft’s IIS server. ASP pages can be written in VBScript or JScript, or most any other language. To that end, ASP is more similar to CGI than any particular programming language.

All that said, both PHP and ASP have a large number of security issues. Most can be eliminated by good programming and administration practices; some, such as the occasional buffer overflow, are problems with the products themselves that can be solved via software updates. PHP, being open-source, generally has a much faster release cycle for these kinds of critical problems, though (IMHO) the language and compiler design leaves something to be desired.

---

<div class="post-metadata">

**Author:** ![Duckster](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/duckster/32/1244_2.png) [@Duckster](https://boards.straightdope.com/u/Duckster)\
**Post date:** [March 2, 2007, 11:12pm UTC](https://boards.straightdope.com/t/asp-not-the-snake-vs-php/394363/3 "2007-03-02T23:12:27Z")

</div>

[QUOTE=Epimetheus]  
My Database teacher, claims that PHP is very insecure, and most businesses use ASP because it is much more secure.  
[/QUOTE]

Perhaps you could challenge your teacher to specifically cite examples of the alleged insecurity of PHP vs the alleged superiority of ASP. After all, as a learning exercise you would think such examples would be beneficial to students trying to learn the correct way to do something rather than just tell them something is wrong without explanation.

---

<div class="post-metadata">

**Author:** ![Rysto](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@Rysto](https://boards.straightdope.com/u/Rysto)\
**Post date:** [March 2, 2007, 11:46pm UTC](https://boards.straightdope.com/t/asp-not-the-snake-vs-php/394363/4 "2007-03-02T23:46:52Z")

</div>

It is possible to write a secure PHP application. The problem is that PHP doesn’t encourage you to write a secure application, and makes it quite easy to write an insecure application. For example, a lot of people construct SQL queries as follows:

“SELECT FROM users WHERE userid=” + $USERID

A lot of hacks have been added to the language to try and make this kind of thing secure(magic\_quotes, mysql\_escape\_string, mysql\_real\_escape\_string) when really, parameterized queries are the way to go. Now PHP does have parameterized queries, but you have to know about them to use them, and pretty much all tutorials don’t use them.

Coincidentally, March is [the Month of PHP bugs](http://www.php-security.org/). At least one new PHP security bug will be unveiled every day this month – and by today(March 2nd), they’re already up to 5 bugs.

---

<div class="post-metadata">

**Author:** ![Turek](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/turek/32/18782_2.png) [@Turek](https://boards.straightdope.com/u/Turek)\
**Post date:** [March 3, 2007, 12:03pm UTC](https://boards.straightdope.com/t/asp-not-the-snake-vs-php/394363/5 "2007-03-03T12:03:59Z")

</div>

[QUOTE=Rysto]  
It is possible to write a secure PHP application. The problem is that PHP doesn’t encourage you to write a secure application, and makes it quite easy to write an insecure application. For example, a lot of people construct SQL queries as follows:

“SELECT FROM users WHERE userid=” + $USERID

A lot of hacks have been added to the language to try and make this kind of thing secure(magic\_quotes, mysql\_escape\_string, mysql\_real\_escape\_string) when really, parameterized queries are the way to go. Now PHP does have parameterized queries, but you have to know about them to use them, and pretty much all tutorials don’t use them.  
[/QUOTE]

But ASP has the same problem. Most books only mention parameterized queries in passing if at all.

---

<div class="post-metadata">

**Author:** ![Sage\_Rat](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/sage_rat/32/399_2.png) [@Sage\_Rat](https://boards.straightdope.com/u/Sage_Rat)\
**Post date:** [March 3, 2007, 12:43pm UTC](https://boards.straightdope.com/t/asp-not-the-snake-vs-php/394363/6 "2007-03-03T12:43:54Z")

</div>

I honestly can’t think of a reason why one would be more or less secure.

JSP and C based CGI applications, etc. at least have static typing, so there’s a better chance of catching run-time errors and buffer overflows. Neither ASP nor PHP do though, so I’d say that as far as a simple language (or platform in the case of ASP) can go in terms of security, there’s no real difference.

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [March 3, 2007, 4:19pm UTC](https://boards.straightdope.com/t/asp-not-the-snake-vs-php/394363/7 "2007-03-03T16:19:50Z")

</div>

An interesting question for the instructor is whether he is talking about ASP or [ASP.Net](http://ASP.Net). If he’s not sure, or asserts that the two products security-worthiness is the same, he’s proven he doesn’t know what he’s talking about.
