PHP Programming 101

July 10th, 2010

Reading the current time: time() and microtime()

Posted by Conrad in Basic Programming, PHP


int time ( )
mixed microtime ( [bool get_as_float])

PHP has a basic function to get the current time in epoch format: time(). Time() takes no parameters, and returns the current timestamp representing the current time. As time() is the first function we have looked at, here is an example script:


print time();
$foo = time();
print $foo;
?>

As you can see, we can either print the return value of time() directly, or we can store it away in a variable then print the contents of the variable – the result is identical.

Working in Unix time means you are not tied down to any specific formatting – you do not need to worry about whether your date has months before days or vice versa, whether long months are used, whether day numbers of day words (Saturday, Tuesday, etc) are used, and so on.

Furthermore, to add one to a day (that is, to get the date of tomorrow), you can just add one day’s worth of seconds to your current timestamp: 60 x 60 x 24 = 86400. So, adding or subtracting 86400 to a date moves forward by one day, and so on – easy, really.

For more precise time values, you can use the microtime() function. When called without any parameters, this returns the current system time in seconds and microseconds, ordered microseconds first. For example: 0.82112000 1174676574

If you pass true to microtime() as its only parameter, PHP will return the time in a more obvious format – seconds.microseconds, like this: 1174676587.5996

When using microtime(), keep in mind that the return value is a floating-point number. There is a setting in your php.ini file called “precision”, which sets the number of significant digits to show in floating-point numbers – note that is significant digits, not decimal places, which means your return value from microtime() may not be as precise as you want. Above, for example, you can see we only have four decimal places returned – this is because php.ini defaults precision to 14, and there are ten digits before the decimal place.

If you increase the value of precision up to, say, 18, and run microtime() again, you will get results that are more accurate: 1174677004.8997819.

Source

December 17th, 2009

6 Tips For Better Form Design (3/3)

Posted by binary in PHP


INFORM THE USERS ABOUT INPUT LIMITS

When your database has a field limit, situate a size limit on a text box – this stops people from entering too much text only to find out that their data has been trimmed down by your database.

KEEP FORMS SHORT
Never make forms too long and verbose- this may cause confusion to people and may intimidate them.

TELL THEM WHERE THEY ARE
In case of splitting forms by pages, it is a good idea to let your visitors know how far they are through the process of form submission. This lets people know where they are at the process all times.

November 15th, 2009

6 Tips For Better Form Design (2/3)

Posted by binary in PHP

ERROR HANDLING
When there is an error within a field, always put a notice next to it and a message at the top indicating the user about the error – if you don’t put the message at the top, people will not notice that there is an error, and if you don’t put a notice near the problem field, people might not tell it from the others.


MARKING NECESSARY FIELDS

Always mark required fields – either with bold text, or, more commonly, an asterisk *. This is to make the users aware that the essential fields must first be satisfied before proceeding to the next step.

To be continued…

October 12th, 2009

6 Tips For Better Form Design (1/3)

Posted by binary in PHP

The use of forms is the main method in which users can send data to the scripts, so it is essential to get them right. Aside from the coding aspect of forms, there are a number of basic usability guidelines to follow to further improve the effectivity:

TABLES

The use of tables will make the layout of the elements appear neat and organized. Tables make the form easier to read, and it would also be easier to report individual errors that occur on fields. Also tables can also be utilized to give the form a design that would be pleasing to the eye without sacrificing practicality.

To be continued…

September 19th, 2009

SERVER REVIEW: APACHE vs. IIS (cont…)

Posted by binary in PHP

(cont…)

On the other hand, Microsoft’s Internet Information Server (IIS) is a group of internet servers which has additional fetures for Microsoft operating system such as Windows NT and windows 2000 operating system servers. IIS can’t use Java, Perl and PHP on a .Net platform because Microsoft doesn’t support those technologies but Web developers can use Microsoft’s Active Server Page (ASP)technology otherwise. IIS has server administrators which include console from which all services and users can be administered. According to www.microsoft.com “I IS 6.0 which is redesigned with a new fault-tolerant process architecture that greatly boosts the reliability of Web sites and applications. IIS 6.0 isolates Web sites and applications into self-contained units called application pools, which separate applications from the other applications that are hosted on the same server.” Now i give you free hand to choose on what server you want to use? IIS or APACHE?

ssl-iis51.gif

Image Source: www.trustis.com

August 16th, 2009

SERVER REVIEW: APACHE vs. IIS

Posted by binary in PHP

Apache is an open source http server named after the Native American. It is then first release in the year 1995. Now a day, Apache is considered as the most used http server in the world. It is compatible with almost all operating systems like Linux, Windows, Mac and etc. Almost anyone can adopt with this http server because of its source code is freely available. The Apache 2.0 which comes with a new Windows optimization technology called the Apache Portable Runtime (APR) while previous Apache version were not optimized for Windows. Apache developers can use Java, Perl and PHP on a .Net platform.

to be continued…

4229-apache-server.jpg

Image Source: www.pdftown.com

July 15th, 2009

OPENSOURCE DATABASE: MySQL

Posted by binary in PHP

MySQL is a Database Management System (DBMS) that is released in May of 1995. It’s commonly use for web applications and acts as the database component of different Platforms such as Linux/BSD/Mac/W-A-M-P/Perl/Python and for open-source bug tracking tools like bugzilla. MySQL are essential components of content management systems such as Joomla, Word Press, Drupal and some Bit Torrent trackers that is written in PHP and uses a MySQL database. The latest MySQL product version is the MySQL 5.0 that is launched last August 2007. It has two different variants such as MySQL Community Server and MySQL Enterprise Server. And soon to release is the MySQL 5.1.

logo-mysql.jpg

Image Source: www.openlife.cc

June 22nd, 2009

PHP Browser Checking Script

Posted by Conrad in Basic Programming, Information, PHP

Several factors are to be considered should one be involved with deploying projects over the internet. One of the things you could do would be to have a nifty script that checks for the particular browser your clients might be using. This can be done with a simple and short piece of code that can mean the difference between a successful deployment without problems allowing proper extensions and plugins to be included. A sample of the code can be seen below for your reference which makes it easier for your program/web page to know which set of scripts and what parameters to adhere with. (more…)

May 22nd, 2009

WordPress – The Best and Worst of PHP

Posted by Conrad in Information, PHP

WordPressThe web publishing platform is the most used blogging platform the world over, many thanks to PHP, the scripting language on which it has been published and is continuously being improved upon. Many in the open-sourced community have however been saying that there are still a lot of vulnerabilities with the system that uses code injection and many more that the many developers who have been developing and deploying it that remains to be fixed. Many of these target their AdSense links that is being used to boost rankings for bogus sites. The web is filled with pits and holes that are constantly being fixed with newer versions of the platform coming out to address these issues. (more…)

April 22nd, 2009

Zend continues to Grace the PHP Scene

Posted by Conrad in Information, PHP

ZendOne of the best companies that have been developing tools for PHP, Zend has continued to provide solutions such as development tools and community resources to help developers and budding programmers the world over. Their enterprise edition ZendCore offers developers the stacks they need along with the tools you get from their web site to get you down and fast to developing web applications and pages in minutes. Ideal for enterprise applications, they offer valuable enhancements to the development stage with tools and many other useful tips for all. (more…)

Next Page »