A hash (also called a hash code, digest, or message digest) can be thought of as the digital fingerprint of a piece of data. You can easily generate a fixed length hash for any text string using a one-way mathematical process. It is next to impossible to (efficiently) recover the original text from a hash alone. It is also vastly unlikely that any different text string will give you an identical hash – a ‘hash collision’. These properties make hashes ideally suited for storing your application’s passwords. Why? Because although an attacker may compromise a part of your system and reveal your list of password hashes, they can’t determine from the hashes alone what the real passwords are.
I suggest that every PHP programmer get acquainted with hashing, as it can be very useful for recognizing valid data. I explain the simple usage in this two-part tutorial.
Here is a tutorial with a remake of the game my friend made. Note, this is not his source code. I made it right on the spot. Also, my mic was off the first time, so this is a voice over.
This three-part tutorial goes over using arrays, loops and sessions to create a simple grid based game. There is no true object to the game other than to move around and hit your head on the boundaries (the edges of the grid).
In PHP, it is really useful to be able to open files and get the information out of them. You can also use files you get the contents of and manipulate them like a template. By using file_get_contents I am able to get the contents of other files, manipulate and output them.
Sometimes it is necessary to destroy a session. If you are familiar with a log in system, usually there is a “Log Out” too. Essentially, when you log in, you have a session, when you log out, that session is destroyed so others cannot latch onto the old data and leach out your personal info for their nefarious purposes. Here I demonstrate a quick and dirty not-so-realistic log in system and a way to log out. I also prove that the session is destroyed by showing a certain page’s differences when I am logged in and not.
There are times where we don’t want every page to depend on form submissions and we want some of the data for and about the user to be retained throughout their session. A session is a length of time that something happens. In this case, the user’s data is kept from each page until the session is destroyed by their own choice(or yours), or they are not active for a length of time and it is dropped. We can access and change this data by using the $_SESSION variable. This is like a cookie, but temporary and the user has absolutely no access to it except a ticket with their Unique generated ID. Please watch this two-part tutorial to learn about sessions and how to apply them.
In this three-part tutorial, I make up a dynamic story as I go along using a lot of the functions that I have taught about before. If you would like to see another way of applying variables and functions called array, count, date, echo, mktime, and rand: it is highly suggested you take your time and watch this tutorial.
Sometimes we need to make up a timestamp to save in a database, or to compare with other dates. mktime() essentially creates the same thing that time() does but according to the dates you provide inside of mktime(). Here is the form that you would put in it.
mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )
the brackets mean that they are optional values, however, since the first is optional, and you want to fill in say the 4th, you will have to fill in all the parameters until that point.
In PHP, you can get the current time through several methods. You can use the self-explanatory time() function, or you can use the date function with a format parameter for what to return.
For example:
echo date(‘l jS \of F Y h:i:s A’);
returns something like Monday 8th of August 2005 03:12:46 PM…
If the title confuses you, don’t fret. My tutorial will explain it to you. Strings, as we know in compu-speak is text. Well, if you want to get part of the text but not all of it, you can use substring. Then if you want to find the position of some text to use in the substring function , you can use the function for that to find the matches for what you put in. However, if there is no match it will default to 0.