Jump to content

Hit Counter Code giving ERROR


vishalonne

Recommended Posts

Hi All

I am getting an warning on my web page when I uploaded the page on server I just writing a PHP PAge Hit Counter-

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/cbsecpsn/public_html/csnip/form_453570.php:7) in /home/cbsecpsn/public_html/csnip/counter.php on line 2

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/cbsecpsn/public_html/csnip/form_453570.php:7) in /home/cbsecpsn/public_html/csnip/counter.php on line 2

 

This is the output - Total page views = 1

 

 

Here is the Code -

Counter.php

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

 

And I used it like this in Survey_Form.php

 

<div class='sfm_cr_box' style='padding:3px; width:350px'>
<?php
echo "<hr><div align=\"center\">";
include_once "counter.php"; // this will include the counter.
echo "</div>";
?>
</div>

 

What is the problem with the code?

Link to comment
https://forums.phpfreaks.com/topic/266632-hit-counter-code-giving-error/
Share on other sites

Hi

Thank you for looking in my problem, actually I want to display hit counter at the bottom of the page. Do I need session...?????

I just want to keep track how many of visitors came to this page.

 

Is it possible without session??

 

My problem is simple for you but for new one like me it confusing

I found this code from Google

<?php

$filename = 'hitcount.txt';
$handle = fopen($filename, 'r');
$hits = trim(fgets($handle)) + 1;
fclose($handle);

$handle = fopen($filename, 'w');
fwrite($handle, $hits);
fclose($handle);

// Uncomment the next line (remove //) to display the number of hits on your page.
//echo $hits;

?>

 

And I have to put this code where I want to display the counter like this

 

<p>This web site has had <b><?php include("counter.php"); ?></b> hits since January 1st, 2007.</p>

 

This will open a txt file and write in it. Is this OK?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.