Sunday, March 19, 2006

Very Useful PHP function - find out where output started!!

I have been programming with PHP for nearly three years and still I am discovering incredibly useful functions. One such that I found today was the headers_sent() function. This functoin returns a boolean value, indicating whether or not the HTTP headers have been sent and more importnatly whether output for the body of the request has started.

It is useful to know this in web programming becuase once the HTTP headers have been sent to the user and the body of the reuqest is being sent, no additional headrs can be sent and attempting to do so will fail.

But, this function does more than tell you whether the headers have been sent, it tells you when and where they have been sent. By passing two arguments to the function it will also tell use the file and line number where they were sent and the main body of the request is output.

While debugging big applications which include code from several files, I often find myself hunting for a rogue ehco or print_r statement that I was using to check data and program flow. With the headers_sent function, the offending statement can be found in seconds.

This is what I did. I edited my php.ini file to add a file to the end of all scripts using the auto_append_file directive. In this file I put three lines of code:

    
if (headers_sent($file, $line)) {
echo("<p><b>Output started by {$file} on line {$line}</b></p>");
}


Simple, elegant and extremely useful.

Saturday, March 18, 2006

Goto My PC for FREE!!!

I was originally going to post this here, but decided to put it on VBF as a tutorial doesn't really suit a blog.


Enjoy.

http://www.vbforums.com/showthread.php?t=393847 - Services like GotoMyPc, allow you to access your computer securly from any location in the world via a web interface. But, at a price. In this case $17.95 per month. This in my opinion is a little bit costly as I have worked out how to do it for free.

Saturday, March 04, 2006

XML is Sexy

Over the past few weeks I have been delving into the applications of XML and I must say that I have been pleasantly surprised, not only by the level of support out there for XML but also by its versatility and simplicity. This is a technology that, for the best part I have ignored until now, I fear that many other developers do the same unless forced to use it.

My latest article at PHP builder is going to be about XSL transformations. XSL (extensible stylesheet language), enables one to describe one type of XML in terms of another. Carrying out a transformation using the stylesheet effectively means that you can convert from RSS->XHTML, WML->XHTML, XHTML->WML, in fact you can convert any kind of XML to any other kind of XML.

Doing this research has also put a few more aspects of web development in perspective. Mainly XML's most popular application (XHTML) and its partners in crime, CSS and JavaScript. I see now the importance of separating these three technologies when designing web pages and ensuring that any CSS and JavaScript is included in separate files via links.

For XML the future looks bright, it does have a lot of potential, some of which is already being milked (look at the Firefox web browser for example). As web technologies continue to merge with desktop applications and personal Internet connections continue to increase in speed, XML will be creeping in the background, enriching an revitalising our online experience.

Friday, February 03, 2006

The woes of OOP!!!!

Well, here I am again. I am still looking after the site at work. I have been asked to add a new facility to the site. The modifications required would result in my opinion in poorly maintainable code, so have decided to rewrite the backend using OOP - this will enable me to update the backend database (this was not a requirement before), easier.

Thinking in the OO way and trying to model things using OO is a lot easier said than done. In the real world modeling an OO system is a lot harder, I have become akin to converting real world problems per se to computer speak procedural steps. With OO, you need not convert and need to try and think of the problem in terms of lots of small entities interacting. This has meant that in some cases where my procedural up bringings have kicked in, the code has become bitty. Not a problem when it is in the right place; finding the right place to implement a piece of functionality however it isn't easy.

Slowly however, I am getting there. I have asked for some extra time to get the new feature up and running and convinced them that in the long term the site will be easier to maintain and update. I am confident that I will get my head around it and will be sure to post an update.

Sunday, January 22, 2006

Long Time No Post

It has been a while since I have dropped by here, a lot has been going on.

I have just started writing articles for PHP Builder and provided my writing skills are up for that challenge, I think it would be quite successful. So far most of my communication with other people has been direct through threads at my main forum www.vbforums.com. I have and are in the process of writing some tutorials to post there.

I find article writing a lot harder however as the audience is a lot broader. Not only are people who are new to the subject going to be reading them, but also those who are not so new, those who are browsing for a specific piece of information or answer and those who are experts and looking to critique the work. A good article in my opinions should satisfy all these and this is what I am hoping to achieve in my articles.