How to make a Hit Counter using PHP
Hello all! in this post i m going to show you how to make a web hit counter using PHP.It is a very easy and useful hit counter which can display the total number of visits made to your website.In this post you will also learn the file handling capabilities of PHP.Following is the complete code of counter.The file counter.dat is already created on the server, than this file is read and incremented everytime your webpage is requested by a browser.
Simple PHP Gridview
If someone is migrating from ASP.Net to PHP than he must be searching for Gridview kind of funtionality in PHP.Basically this kind of job is accomplished in PHP by populating an HTML table at runtime i.e extracting each row from the database one by one and than build a table dynamically.Following code is doing the same...
Creating a Database from within PHP
Creating a database from the PHP code on runtime is very simple by using a combination of Structured Query Language and the PHP mysql_query() function.
Steps to communicate with MySql database using PHP
If your PHP web application is dealing with a database most commonly MySql,The knowledge about the following functions and their order as described is better.
- mysql_connect(hostname,databaseUserName,databasePassword):This is the first function which will establish a connection with the database.It returns false on connection failure.
- mysql_select_db("databaseName","connectionName"):This function selects the database.It takes database name and connection name as parameter, Note that connection name is optional.This function can also return false in case of any error.
MySql Connect : The mysql_connect() function.
MySql is the database mostly paired with PHP to provide robust functionality of Interactive webpages.To establish any communication with database in MySql, it is necessary to connect with the database.
PHP inlude() Function
If some lines of code are to be included in every page of the website, The PHP include() funciotn works perfect.If you have been working in ASP.Net or in Dreamweaver than you must be familiar with the role of masterpages and frames in ASP.net and Dreamweaver respectively.Suppose if the look and feel of the website has to be kept similar than we can include the navigation and header files on every page using PHP include() function.
How to get the name of PHP script
To extract the name of the currently executed script from the URL, The PHP superglobal array $_SERVER can be used.The example below describes the procedure.
How to get IP address of visitor in PHP
Getting the IP address of the visitor is the simplest task in PHP.Look at the following example:
$userIP = $_SERVER["REMOTE_ADDR"];
echo $userIP;
?>
PHP Cookies
A cookie is used to identify a user.Some information about the website's user are stored at the user's computer so whenever the same user sends the request through a browser software, the stored cookie can be utilized to identify that user.
Like every good web programming language, PHP also provides a very useful and easy mechanism to accomplish the concept of cookies.The setcookie() function will create a cookie in client computer, it is must that the setcookie() function should be called before the HTML beginning code.