Archive for the ‘PHP’ Category

Page Registration

Monday, August 22nd, 2011

This tends to be a no-brainer but some pages do ask a tad bit too much from possible readers/users by asking too many questions. The easiest and simplest way of verification would be the basic username, email and password and you could go a long way with those three. Adding more makes a page/site look hostile thus swaying potential users form even getting in.
Imagine trying to get membership into a page that slaps you with a 15 to 25 field questionnaire, discouraging, right? Keep it simple and effective for all these information once collated can be a lot to handle even for the best of pages and hosts.

PHP Programming 101

History – a story of breadcrumbs

Monday, August 22nd, 2011

We all know the fairytale Hansel and Gretel where two kids use breadcrumbs they left along the way to get back home. That would greatly help users of your page to get a sense of control of where they are on your page. Most pages fail to do this preventing proper usage or not maximizing all the potential information your user can get from your page.

Control allows users to view through a simple “Home > About > Sub Page Title” line where they are at and should they want to get back to the second tier of the page, a simple click is all it takes rather than several on the browser history button.

PHP Programming 101

Print Style Sheets

Sunday, August 21st, 2011

It may not be essential for a page to function but users of content / blogging sites might want to print your content would greatly appreciate it. May it be for review later or uploading to their e-book for reading on the go, having this function provides a portability factor to your content allowing it to go farther.

Yes, plagiarism is issues all over the internet but hey, if you don’t want that information to be used then why place it into the internet. We all know that anything on the internet is fair game for everyone so having a decent site with decent followers can be insurance enough to avoid the issue.

PHP Programming 101

Page Not Found!!!!

Friday, August 19th, 2011

The annoying result of clicking on an image or link that presents nothing that can sway potential readers from continuing to explore a page. This would take a bit more reviewing of the code and other content but it ensures reliability and functionality enough to get your followers the information they need when they need it.

Sure you cannot anticipate or review them all but a periodic check should always be done to ensure this. On blogs, the short-links may have been erroneously saved when you changed the title of that article you saved as draft then published. Take time to place yourself in the footstep of the user and try out your page to isolate and fix such issues.

PHP Programming 101

PHP and other Programming Languages

Friday, March 19th, 2010

The major notable difference with PHP against other languages with regards to variables is that PHP is more “intelligent”. In C for example, variables have to be explicitly defined as either numeric or alpha-numeric and can only be used to store that defined specific form of data. PHP like all other languages supports a lot of variable types such as integers, floating point numbers, arrays and strings but with one major difference, variables are recognized automatically based on their use and the context of their use. This makes your (programmer’s) life a whole lot easier. PHP variables are defined with a “$” symbol preceding the variable name. It should also begin with either an underscore or an alpha character.

PHP Programming 101

More Programming Basics

Sunday, March 14th, 2010

As with all programming languages PHP has different variable types such as numeric, character, string and Boolean types. Boolean variables in PHP always return either true or false, integers are whole numbers, floating points are decimal or scientifically notated and strings are a chain of characters. Sounds familiar, well they are and they are mostly standard across the various programming languages. For a more in-depth discussion on the different data types of PHP go visit the manual page.
We next discuss operators such as the assignment operator which allows you to assign values to variables allowing complex operations to be constructed into more and more functional programs.

PHP Programming 101

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

Sunday, February 21st, 2010


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

PHP Programming 101

PHP Security

Wednesday, January 27th, 2010

php-security7.jpg

More than a quarter of all software vulnerabilities identified among the Common Vulnerabilities and Exposures (CVE) listed and recorded in the National Vulnerability Database is related to PHP. This makes PHP susceptible to hackers who develop scantily built applications written in PHP. Most of these vulnerabilities can be slightly exploited without being logged on the computer hosting the exposed application. Because of bad programming habits such as failing to check data before entering into a database, and certain features, such exploitation is possible.. This kind of attacks is not limited to PHP and can mostly be avoided by following the appropriate coding procedures and principles.

Easy PHP Programming

Array Chunk Function

Sunday, January 17th, 2010

The array_chunk() function on the on the other hand as the name implies, divides an array into chunks or several tables from the source table. The syntax goes something like array_chunk(array,size,preserve_key), wherein the array is the table that would be divided, the size is the number of elements which the new arrays are to contain and the preserve key which can either be true or false is used to either retain or revise the key or pointer value of the original table. An example is shown below:

$a=array(�a�=>�Cat�, �b�=>�Dog�, �c�=>�Horse�,�d�=>�Cow�);
print_r(array_chunk($a,2);
?>

The code would have an output of:

Array (
[0] => Array ( [0] = > Cat [1] => Dog )
[1] => Array ( [0] => Horse [1] => Cow )
)

As we can see, the original array has been divided into two arrays array0 and array1 and a value that is not given for the key had it assigned a new key for each of the tables. Another example would be :

$a=array(�a�=>�Cat�, �b�=>�Dog�, �c�=>�Horse�,�d�=>�Cow�);
print_r(array_chunk($a,2,true);
?>

This would then give us ;
Array (
[0] => Array ( [a] = > Cat [b] => Dog )
[1] => Array ( [c] => Horse [d] => Cow )
)

This shows the significance of the retain key field wherein the two new arrays retained their original keys. The reverse of which would be the array_combine() which divided the array into one which holds the keys and one with the values.

Easy PHP Programming

Good Domain Name (Part 1)

Saturday, January 16th, 2010

Photobucket

Before choosing a domain name, consider the following:
1. Domain Name as your website Name
It is important to name your site after your domain name so that when people think of your website, they’ll remember it by name. If it is also your URL then it is much more easier to remember. Your domain name should reflect your site or business.

2. Brand Name Domains
Domain name that matches your brand name is better as usually if people are thinking of buying something they already have a particular brand in mind.

3. Hyphenated Names
Hyphens in websites are usually easier to forget. But if you really want a particular domain name but it is already taken, with a hyphen you can shave the domain name you want.

PHP Programming 101