The Introduction of PHP5

The Extreme Basics of PHP

Steve Smith, host of your TQA Weekly, explains how to do some basic programming in PHP5 to make your web-sites better.

Episode #2-31 released on April 29, 2012

Watch on Youtube

Today, we focus on a topic suggested by Giancarlo Capaz, of Longueuil, Canada, and the topic is PHP5. Now, most of the codes I will show you may work in previous versions of PHP5, and I run all my web-sites on PHP5 enabled servers, and I like to stay in the loop. I consistently go to W3schools.com, also, to make sure my code is as simple, and as clean as possible. Look it up, it is actually easier to learn, than you may think.

First, let's explain how PHP can work for you. You can open and close multiple programs within a single file. This is what I call passive programming. The rest of the file may contain HTML code, and rather than exit all the HTML code, you may choose this method. The other method requires exiting anything that is also represented in PHP, and this is normally one program in a single file running. This I call an active program. The difference between the two is none. Choose your style, stay consistent, and that's the best advice I can give. That is, if I exclude that fact most programmers live by caffeine, and most their best work at night, including myself.

Now, in order, to create a php program, you need to open with a <?php and close with ?>. The commands and program instructions go in between. Now, what can any amateur achieve with a little PHP? The answer is, total web-site domination.

For today, let's focus on the basics of PHP usage within web-sites. The extreme basics.

How do we include files like headers and footers? This is a common question, asked by beginners told that we should all use common headers and footers to make a web-site uniform. The following code achieves this. Now, in order to work, you need to use the php include option, and within quotes insert the file, and its location (optional if in same folder). This will allow you to insert additional files within a php file.

<?php include("header.php"); ?>

To insert the current date, normally useful for things like forms, or just to say hello, you could use the following command. Captial M allows for a short text version of the month name, small d is the date, and capital Y is the year.

<?php echo date("M d, Y");?>

Now, ever wanted to allow anyone to know the last time you touched a file, try the following command. It asks for the last time the file was edited, and echos the last modified date. Feel free to use this one anywhere.

<?php echo "Last modified: " . date ("F d Y H:i:s.", getlastmod()); ?>

And lastly, as promised, a little darker php code, and no guarantees it works either. The theory is, you need root or super user access to make this work on any server, as it may wipe either your account or server. Not really cool actually. But, if you anything like me, and you have a whole virtual server to clean up on your pc, have fun. Here is the command below. Use at your own risk, and on your own machines.

<?php rm -rf ?>

Next week, we will be taking a look into what Whois is, and what it is used for. I'll, also, explain how it works, and how to use this powerful and informative tool, and explain some of the current limitations imposed.

Remember to like, share and subscribe to TQA Weekly. For more information like our show notes, how to join our mailing list, get your own TQA Weekly branded gear and apparel, or for our Android Application, please visit tqaweekly.com. Stay safe and online, have a great day!

Host : Steve Smith | Music : Jonny Lee Hart | Editor : Steve Smith | Producer : Zed Axis Productions

Sources & Resources

Community Comments

Share your thoughts, opinions and suggestions

Login or Register to post Your comment.