· 9 years ago · Nov 08, 2016, 06:24 AM
1<?php
2
3session_start();
4
5$con=mysql_connect("localhost","root","");
6$db=mysql_select_db("phpcount");
7
8$webpage=htmlspecialchars($_SERVER["REQUEST_URI"]);
9
10$sql = "CREATE TABLE IF NOT EXISTS counter (
11id int(4) NOT NULL auto_increment,
12webpage varchar(90) NOT NULL,
13visitors int(11) NOT NULL default '1',
14PRIMARY KEY (id)
15) ENGINE=MyISAM AUTO_INCREMENT=1";
16
17mysql_query($sql);
18
19$result=mysql_query("SELECT * FROM counter WHERE webpage='$webpage'");
20$num_rows = mysql_num_rows($result);
21if ($num_rows == 0){
22mysql_query("INSERT INTO counter (id, webpage, visitors)
23VALUES ('','$webpage','1')");
24
25}else{
26
27if (!isset($_SESSION['webpage'])){$_SESSION['webpage'] = 0;
28mysql_query("UPDATE counter SET visitors=visitors+'1' WHERE webpage='$webpage'");}}
29
30?>
31<html xmlns="http://www.w3.org/1999/xhtml">
32<head>
33<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
34<title>Counter</title>
35
36</head>
37<body>
38
39<?php
40
41$result=mysql_query("SELECT * FROM counter WHERE webpage='$webpage'");
42$row=mysql_fetch_assoc($result);
43$n=$row['visitors'];
44$l=9-strlen($n);
45$z=substr('000000000',0,$l); ?>
46<p class="big">
47<?php echo "<div class='counter'>".$c."</div>"; ?>
48</p>
49<p class="title">
50<?php echo $c="Counter: ".$z.$n; ?>
51</p>
52<?php
53mysql_close();
54//session_unset();
55//session_destroy();
56
57?>