Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.