Wednesday, 1 January 2014

Create Simple Profile Visitors in PHP - learn more @i-vision blog

Today We are living in Profile world. In the real life we would see how many will visit our profile and check our status.But in Profile world how could we know.many were asking about it.Many were using facebook app like Profile visitors and posting some images on their wall.I hope facebook does'nt have the option since it may hinder privacy of visitors. And this app may be to a prank!.so,lets built a Simple PHP based profile visitor for Your cool website in PHP.

Why  track visitors?

your website may have a large amount of visitors day by day! and this stats may help you to increase your confidence and may increase your standard of your website.The main purpose of website is for viewers to display them in websites and generating traffic daily.this can be monitored with the help of stats counter.And if you may built a social networking site ,This cool feature may introduce many fans for Your site.

How Simple We Could Code them?

Creating Profile visitors table in Database is quite easy.The Unique Way of identifying the visitor is getting their Ip address and Timestamp from them and saving the database.so,in PHP how could we get the IP address of the client and Tine when they enter the Site.In addition to this we may have browser list also.which could add more experience for Admin to track the most visited browser and change the settings accordingly!
so, here i'm using:
time() for Timestamp function to note down the time of the user entering Your site.
$_SERVER['REMOTE_ADDR'] for noting down the IP address of the users entering your site.
$_SERVER['HTTP_USER_AGENT']; for noting down the Browser they have used to view your site.

we are going to mix this three variables in PHP

<?php
include('config.php'); //connection to database
$ip=$_SERVER['REMOTE_ADDR']; // identifying and saving the clients ip address
$time=time(); //obtaining clients time
$browser=$_SERVER['HTTP_USER_AGENT'];  //getting browser
$s=mysql_query('insert into profile_visitor (ipaddress,time,browser) values ("'.$ip.'","'.$time.'","'.$browser.'")');
?>

here we just Get the variables of IP address and Browser client are obtained. and save it is in Table.

Generate the table accordingly for codings :
1)id -can be primary-11(autoincreament)
2)ipaddress-int-100
3)time-int-100
4)browser-varchar-1000

thus you can run it in your browser and verify your table.If you're testing it from local host it may be noted as 127.0.0.1.

Now we are going to query the details from table of database as Admin.

<?php
include('config.php'); //connection to database
$s=mysql_query('select from profile_visitor order by time desc');
$row = mysql_fetch_array($s);
$num=mysql_num_rows($s);
$i=0;while ($i < $num)
{  ?>
<span id="shivasurya">ip:<?php echo $row['ipaddress']; ?>--time:<?php echo $row['time']; ?>--browser:<?php echo $row['browser']; ?> </span>
<?php
}  ?>

the above code generates the visitors time and ipaddress,browser name for admin.

If you are constructing Social Network Or profile based sites you may use Id of the user and the user name for every visits and group them accordingly and visits.
visitors
There is no application in facebook that can track the recent visitors.feel free to comment below!



0 comments:

Post a Comment