Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

How to see number of visitor visited our website using session in php codeigniter.

I have tried but each system continues from 1st session.

What I have tried:

session_start();
if (!isset($_SESSION['views'])) {
$_SESSION['views'] = 0;
}

$_SESSION['views'] = $_SESSION['views']+1;
Posted
Updated 28-Aug-16 19:33pm
Comments
Vivek.anand34 29-Aug-16 1:49am    
session_start();
$counter_name = "counter.txt";
// Check if a text file exists. If not create one and initialize it to zero.
if (!file_exists($counter_name)) {
$f = fopen($counter_name, "w");
fwrite($f,"0");
fclose($f);
}
// Read the current value of our counter file
$f = fopen($counter_name,"r");
$counterVal = fread($f, filesize($counter_name));
fclose($f);
// Has visitor been counted in this session?
// If not, increase counter value by one
if(!isset($_SESSION['hasVisited'])){
$_SESSION['hasVisited']="yes";
$counterVal++;
$f = fopen($counter_name, "w");
fwrite($f, $counterVal);
fclose($f);
}

Patrice T 29-Aug-16 4:20am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Vivek.anand34 29-Aug-16 1:50am    
I have used this code it executed... Thanks...
Vivek.anand34 29-Aug-16 1:52am    
Display it : echo "You are visitor number $counterVal to this site";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900