如何在PHP网站的页脚中使用访问者数量 [英] How to use number of visitors in footer of PHP website

查看:81
本文介绍了如何在PHP网站的页脚中使用访问者数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

爵士先生

我的名字是Sarfaraz。我是PHP的新手,我发现了一些代码来计算我网站的访问者数量,当打开该页面时工作正常,但是当我试图将其嵌入footer.php时,我遇到了一些错误。我只是想知道如何在footer.php中嵌入它。

我也在我的网站中包含了这个footer.php。

我在嵌入时遇到了以下错误这在footer.php



Sir
My name is Sarfaraz. I am new to PHP and i found some code for counting the number of visitors of my website which is working just fine when opening that page but when I am trying to embed it in footer.php I am getting some errors. I just wanted to know how to embed it in footer.php.
I am including this footer.php in my website also.
I am getting the folowing error when embeding this in footer.php

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\xxx\index.php:144) in C:\xampp\htdocs\xxx\includes\counter.php on line 2
You are visitor number 9 to this site
Thank you

推荐答案

让我们做一些侦探工作,我认为你的页脚文件被称为counter.php,其中包含第2行的session_start。您已将此文件包含在index.php的页脚中,该页脚也有自己的session_start。这可能是其中一个原因。
如果没有,请查看: warning-session-start-function-session-start-can-send-session-cache-lim [ ^ ]



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++



这是为了回应您的进一步查询而添加的:

1.您显示的php代码正在使用一个文本文件counter.txt来存储访客号码,
Let do some detective work, I think you footer file is called counter.php which contains session_start on line 2. You have included this file into the footer of index.php which also has its own session_start. This could be one of the reason.
If not, check this out: warning-session-start-function-session-start-cannot-send-session-cache-lim[^]

++++++++++++++++++++++++++++++++++++++++++++

This is added in response to your further queries:
1. The php code shown by you is using a text file "counter.txt" to store the visitor number, the "


_SESSION ['hasVisited']在这里是多余的,不需要,下面的代码会做,假设你将它作为counter.php保存在名为includes的文件夹中:

_SESSION['hasVisited']" is redundant here, it is not needed, the following code will do, assuming you save it as "counter.php" in a folder called "includes":
<?php


counter_name = counter.txt;
if (!file_exists(
counter_name = "counter.txt"; if (!file_exists(


这篇关于如何在PHP网站的页脚中使用访问者数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆