porn - javhd - hentai

Learn PHP – dipping your toes in the dynamic web (Part 1)

By   |  June 20, 2005

Over the years, I\’ve experimented with a large number of server-side languages for creating dynamic websites. While there is an almost limitless number of languages that you can beat into some kind of shape for web server deployment, it\’s always been a case of fitting round pegs into square holes.

At best, server-side programming was a drag. At worst, a migraine-inducing spaghetti of complexity that I couldn\’t even begin to fathom.
I was about to give up on this whole \”Internet\” thing in the hope that it was just a fad that would pass, leaving me to live in calmness and Zen harmony with my PC once more, when I discovered PHP. Finally, here was a language that made sense for internet applications, and so simple that even I could use it.

I considered just keeping quiet about my little discovery so I could capture the market in server-side development, make a mint and retire by thirty. Then I was hoodwinked by the open source share-and-share-alike nonsense and realised that you can\’t keep all the good stuff to yourself.

So here is the first of a series of articles explaining the ins and outs of PHP, scuttling my plans of owning a yacht in the Caribbean, but hopefully improving the quality and quantity of serious web applications. The penguin demands it!

Lesson one: Is this thing on?
PHP comes with most Linux distributions and is also fairly simple to install on Windows. The great thing about PHP is that it runs fairly uniformly on just about every web server and platform that you might want to deploy it on, which makes it truly cross-platform. If you don\’t have it installed already, head on down to www.php.net for the correct files, plus some instructions on how to get it running.

I\’ll assume you\’ve managed to install it or have it already and dive into your first application. I use a text editor called Jext to write my PHP code. It also runs on Windows and Linux (being Java based), and highlights the PHP code beautifully. PHP is script-based, so you can use any text editor you want to knock up a PHP site and see the effects instantly. No compiling, no hassle. And, of course, the files are really small.

We\’ll start with a simple test page, which is going to be exceptionally useful to you when you start getting into the hard-core abilities of PHP. I call mine phptest.php ­ note the .php extension. This will let your web browser know that the file needs to be parsed by the PHP compiler at run-time. Save it into a directory accessible by your web server and make sure the permissions allow the page to be seen.

Now the PHP compiler will just print whatever\’s in the file without changing anything unless you place code in between the symbols . Everything else looks like normal HTML. This is really a bonus if you\’ve designed your page in a nice visual page layout program, like Nvu, if you\’re upgrading an existing site to be dynamic, or if you\’re working with a designer and just adding the dynamic components.

We\’ll only be running one command. How\’s that for low-stress programming? The command is phpinfo();. The brackets at the end mean that this command is a function ­ it sparks off another set of commands that have already been programmed. Phpinfo() is one of PHP\’s built-in functions, which means we don\’t have to write the function ourselves. So the source code for our phptest.php looks like:

< ? php phpinfo(); ?>

Note the semicolon at the end of the line. This means that this is the end of the command, and you\’ll see it in a lot of other languages, like Java, Javascript, Perl and C++. PHP borrows a lot of its syntax from other languages, but tends to be a lot easier to use than the others.

I wish I could say that there was more to your first application than that ­ if there was I would have a lot more job protection. But that\’s it! Finito! Hit save and point your favourite web browser (aka Firefox) at it. Don\’t forget to go through the web server ­ your url should look something like: http://localhost/testphp.php. You should get a whole lot of information about PHP. If you get an error message or can see the source code, it means there\’s something wrong with your PHP installation or PHP isn\’t installed at all. Refer to the documentation on http://www.php.net for help on getting it up and running.

Comments

Comments are closed