Codeigniter-创建唯一的页面视图计数器

时间:2019-04-09 08:46:11

标签: php sql json ajax codeigniter

我正在为我的每个页面创建一个访客计数器。根据PageId和visitor Ip,我创建了两个表,例如pageView和pageTotalView。但是我的代码无法正常工作。我在php中找到了一些代码。如何在工作中将这些代码转换为Codeigniter?

数据库表:

CREATE TABLE `pageView` (
 `pageViewId` int(11) NOT NULL AUTO_INCREMENT,
 `pageViewPageId` int(11) NULL,
 `pageViewUserIP` text NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1


// totalview

CREATE TABLE `pageTotalView` (
 `pageTotalViewId` int(11) NOT NULL AUTO_INCREMENT,
 `pageTotalViewPId` int(11) NULL,
 `pageTotalVisit` text NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1

PHP代码:

// gets the user IP Address
  $pageViewUserIP = $_SERVER['REMOTE_ADDR'];

  $check_ip = mysql_query("select pageViewUserIP from pageViewwhere pageViewPageId = 'I dont know How I can get viewing Page Id' and pageViewUserIP = '$pageViewUserIP'");
  if(mysql_num_rows($check_ip)>=1)
  {

  }
  else
  {
    $insertview = mysql_query("insert into pageView values('','I dont know How I can get viewing Page Id','$pageViewUserIP')");
    $updateview = mysql_query("update pageTotalView set pageTotalVisit = pageTotalVisit+1 where pageViewPageId ='I dont know How I can get viewing Page Id' ");
  }

总而言之,这些代码也许可以在php上运行,但是如何在Codeigniter中使用这些代码?

0 个答案:

没有答案