Archive for September, 2006

Comparing ASP to PHP Includes

September 10, 06 by kenrich

When comparing PHP scripts to Active Server Pages, there is a huge difference between the way you use include files. When using ASP, you either have to use Server-Side Includes or the Server.Execute statement to include one script inside another. In PHP, you have a lot more options. You can use “include”, “require” or “require_once” to include a file.

One of the shortcomings of Server-Sidie includes is that you cannot include a file more than once. This causes problems when you want to do a conditional include. In most cases, you will only need to include a filie once. One case where you might want to include a file twice is an admin login check. With such a script, you would check to see if the user is logged in and if not, you would display the login form. Because you want to include a header and footer in the login include and also include the header and footer on any admin page that includes the login check, you will need to include the header and footer twice.

If you declare any variables, constants, classes or functions in the header or footer, you won’t be allowed to include the file more than once. This would give you a “variable already declared” error. Even if the code is contained in a conditiona “if-then” statement, the parser will still process all of the code statements and recognize the duplicate variable declaration. You could used the Server.Execute statement but when you do this, the file is not truly included within the context of the current script. Instead, the script is executed standalone, and the output from that script is inserted into the current script.

PHP eliminates a lot of these problems by providing truly conditional includes. When you put an include statement within an “If then” statement, the code will not be processed until the script is evaluated and the condition is met. This eliminates the problem with redeclaring variabels inside header and footer. Additionally, PHP provides a new statement called “require_once”. This statement ensures that an include statement is only included once. Only when the require_once statement is first encountered, does each unique include file get included.

Returning to a Website Project and Finding Problems

September 07, 06 by kenrich

It’s amazing how when you step away from a project, you believe that everything is working fine. Months later, you go back to work on the project to find out that what you thought was working wasn’t even close. This just happened to me while I was working on my new Team Task site.

I have been going through the forums application and I noticed that posting replies was not working properly. When you attempted to post a reply, the system would instead post a new topic. Definitely not a desirable behavior and something that needed to be fixed immediately. The good news is that this is now fixed and I found some other issues as well.

The HTML used to build the page was rendering differently in Firefox than it was in Internet Explorer. It seems that when using the break tag (br), the two browsers handle them differently when placed alongside paragraph and table elements. The solution was to change my paragraph tags to div tags and now everything looks consistent.

I was also plagued by the Firefox not wanting to abide by inline CSS style attributes. Instead, I placed these styles within their own style element and created ID selectors to reference the style of these elements. It’s a shame that the site has been in a state of disrepair for so long. I hope to get this site running in prime form very shortly.

Brainstorming for New Website Ideas

September 06, 06 by kenrich

Whilst coming up with new business ideas, I often ask myself “What is the most useful tools I’ve found on the web?”. Often, my thoughts turn to things like the Google search engine, the Internet Movie Database or just a reference site such as ASP Nut which contains a quick reference along with some useful articles.

Over the years I’ve found that it’s these sites that tend to attract the most amount of traffic. I’ve become interested in generating more traffic since I’ve started a new campaign with AdSense to sell advertising on my sites.

When my company was originally founded, I used to have a very simple site which would allow a visitor to see his or her IP address as it appeared to the outside world. While this may seen basic to most people who are even somewhat technically inclined, it can be a real chore to the novice computer user. So we just built a single page site where visitors could view their IP on the home page of the site. This site quickly became one of our most popular sites. The irony was that the site only took a couple of hours to build.

So now I find myself in a similar position. I am looking for some useful sites that I can create which will add some real value to the Internet. In doing so, it should prove to be a popular site which receives a lot of visitors. I will be brainstorming for ideas over the next few days. Should you have any ideas you would like to contribute, feel free to add a comment here!