Posts

Showing posts with the label Cookies

Visitor Counter with cookies in PHP

Image
Here we are describing how we can check visitor in a website with he help of Cookies in PHP.
We will setup a cookies in the user Browser for one year.

So we will first check about that particular cookies present in User's Browser. If the cookies is present in the User's Browser (Client Computer) , we have to do nothing on that condition, as the user is old for the that website.

If the cookies is not present in the user's Browser, we will setup the cookies in the user's Browser and update the details on the database for total count for that website, we are using the visitor counter.

So the first condition to check we have is:

is the cookies is present in the Browser:
 For this we have the function on php, which is isset(),  This function is used for checking the variable is set in the Program or not.   The cookies, we will create with the name of "isvisitor"
So the code will be as follow:
<?php
if(isset($_COOKIES))
?>





PHP Variable

Image
Click to Enlarge Here I am Describing Basic of Variable.

There are many type of variable used in PHP.

Following are some:

Variable from GET Method Variable from POST Method Variable Used in a PHP program itselfVariable from SESSION Variable from COOKIES

Variable Type Description GET Method Variable Variable Used as: Array
Using Technique: As Following:
By referencing in URL i.e. filname.php?variable1=value1&variable2=value2 By Sending by FORM method will be GET i.e. By HTML Input fields like text, password, select etc. Validity/ Scope: Till they reference in URl or sent by Forms
Calling as: Called as $_GET['variable1'] and $_GET['variable2'] POST Method Variable Variable Used as: Array
Using Technique: As Following:
By Sending by FORM method will be POST i.e. By HTML Input fields like text, password, select etc. Validity/ Scope: Till sent by Forms and the File is running
Calling as: Called as $_POST['variable1'] and $_POST['variable2']
To be …

Visitor Count for Website in PHP

Hello,
Here I am writing a small program in PHP for  checking how much user have visited our website using COOKIES, MYSQL and IP address of the user.
First we have to create cookies for the new user.

This the code we will use for that: (I have make a cookies for 30 days)
setcookie('ipaddress',$_SERVER['REMOTE_ADDR'],time()+(60*60*24*30));

Secondly we have to create a table on database to store the number of Visitors.
I have created a table i.e. usercounter with following attribute:  (Initially Insert value with o and 1 on useripid )

useripid   (INT type - AUTO-INCREMENT)lastaddress   (VARCHAR    -   Last visitor IP)userqua   (INT)   (Counter for visitor)  (Initially 0)lastmodified   (TIMESTAMP)   (Last modified time for database) Now we have to check whether user are coming on website for first time or He has already visited. if(isset($_COOKIE['ipaddress'])) { // check is the same ip if($_COOKIE['ipaddress']==$_SERVER['REMOTE_ADDR']) {  // nothi…