Help - Search - Members - Calendar
Full Version: hide counter?
HTMLHelp Forums > Programming > Server-side Scripting
xxkasperxx
I am just learning PHP, and have this counter script:

CODE
<?PHP
  session_start();

  if(isset($_SESSION['views'])){
     $_SESSION['views'] = $_SESSION['views']+ 1;
  }else{
     $_SESSION['views'] = 1;
  }
  echo "Total page views = ". $_SESSION['views'];
?>


Is there anyway to get that code to ONLY appear when i log-in and go to the admin panel that i will be creating?
Darin McGrew
You could put the echo command inside an if statement. I don't know what condition you would need to have the if statement test though. Do you know what might indicate when you are logged in, or when the admin panel is being displayed?
xxkasperxx
you will enter your user information... and i have it set to make a Session
ScottD
you may need something like this, but edit it for your session name:
CODE

if (isset($_SESSION['session_name'])) {
  echo "Total page views = ". $_SESSION['views'];
}
Ephraim F. Moya
What are you trying to count?

Random visitors?
Members?
New members?
Something else?

Each one will take a DIFFERENT program.
xxkasperxx
i am trying to count visitors in general
Ephraim F. Moya
QUOTE(xxkasperxx @ Jan 10 2012, 06:29 AM) *

i am trying to count visitors in general


Then you don't need sessions. Just count each time you send out the <head> element.

Do your counting in a database so you don't lose the count between visitors.

For instance:

<?php
Read the MySQL db for the visitorCount variable.
Increment the visitorCount Variable
Put the visitorCount back
echo "<head>";
output the rest of the page.
?>

Brian Chandler
QUOTE(xxkasperxx @ Jan 10 2012, 10:29 PM) *

i am trying to count visitors in general


Then you can't just use the "Sessions" information -- this is there to be carried across any particular session, and rather obviously if you want to look at all the visitors, you will not be part of their sessions.

If you are learning php this seems an odd place to start. You can get info on visitors from your weblogs, which will generally be simpler. Otherwise you have to write a program to save the relevant information from each visitor (login id (etc) and visit count) in a database table.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.