How to Creating A Page Counter In PHP

Fadıl

OK,  everybody has a hit counter on their page.  But how many people actually make their own?  Ya well, I am going to show you how to create a simple page counter in PHP.

This page counter writes to a file that you have created, storing how many hits you have received.  The script then reads the text file (counter.txt) and displays it on the page.  Let’s take a look at this code in action.

Changing Ownership Of A File Using Chown

Fadıl

Recently I encountered a problem when I ftped to my server, I was trying to upload a file that already existed under my username on the server, and I kept getting a 550 error. Which for you newbies out there is a file permission error, telling me that I do not have rights to write over or delete those files under my username.  That made me mad, I didn’t know what was going on I thought my FTP server was messed up.  Then we figured out that the problem could have been who owned the files.  Surely enough, the files were owned by root instead of a pinhead which was the username I was under.  If your files under your username are owned by root then that will allow your file permissions to be limited and you not to be in control of them.  So how do we fix all this?

MySQL’s Status Command

MySQL’s Status Command

Fadıl

The status allows you to see various stats on the MySQL daemon. To get to your MySQL shell, type the following command at your shell:

[icezip@saturn ~/]$ mysql -u icezip -p

(where icezip is your user name for MySQL)

A prompt will come up and ask you for your password, so go right in and enter it. This will bring up a MySQL shell.

Welcome to the MySQL monitor.  Commands end with; or g.
Your MySQL connection id is 18724 to server version: 3.22.32
Type ‘help’ for help.

Writing To A File Using Fopen

Fadıl

Their will be many different instances when you might need to write to a file.  What we are going to do now is create an HTML form, and a PHP code so when you click submit on the HTML form it writes the users input to a file.

In this PHP script, we are going to be using the /n function, fopen, fput, and fclose commands.

First, we are going create an HTML page that has the following code.

Counting Number Of Entries In A Database

Counting Number Of Entries In A Database

Fadıl

Do you have your own database?  How would you like to know how many entries you have in your database from a PHP page?  Well its easy, I am going to show you a script that will allow you to create a counter that will count the number of entries you have in your database.

Now let’s say we have an email database, and we want to count the number of emails we have in the database.  All we need to do is create this simple script (assuming your database is already made).