Start on HW
This commit is contained in:
parent
32d4a62246
commit
15b264ded2
21
homework/2/counterDB/counter.php
Normal file
21
homework/2/counterDB/counter.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once "../../../base/settings.php";
|
||||||
|
include_once "../../../base/database.php";
|
||||||
|
include_once "./impl/functions.php";
|
||||||
|
|
||||||
|
$db = DB::openConnection();
|
||||||
|
|
||||||
|
$start = strlen($_SERVER["REQUEST_URI"]) - 256;
|
||||||
|
$siteID = substr($_SERVER["REQUEST_URI"], $start);
|
||||||
|
|
||||||
|
$visitorCount = getHits($siteID, $db);
|
||||||
|
|
||||||
|
addHit($siteID, $db);
|
||||||
|
|
||||||
|
DB::closeConnection($db);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div>
|
||||||
|
Visitor count: <?= $visitorCount + 1 ?>
|
||||||
|
</div>
|
||||||
3
homework/2/counterDB/impl/.htaccess
Normal file
3
homework/2/counterDB/impl/.htaccess
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Order deny,allow
|
||||||
|
Deny from all
|
||||||
|
Allow from 127.0.0.1
|
||||||
20
homework/2/counterDB/impl/functions.php
Normal file
20
homework/2/counterDB/impl/functions.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
include_once "./impl/queries.php";
|
||||||
|
|
||||||
|
function getHits($id, $db)
|
||||||
|
{
|
||||||
|
global $getHitsQuery;
|
||||||
|
$stmt = $db->prepare($getHitsQuery);
|
||||||
|
$stmt->bindValue(":SID", $id);
|
||||||
|
$stmt->execute();
|
||||||
|
$hits = $stmt->fetch(PDO::FETCH_COLUMN);
|
||||||
|
return $hits !== false ? $hits : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addHit($id, $db)
|
||||||
|
{
|
||||||
|
global $setHitsQuery;
|
||||||
|
$stmt = $db->prepare($setHitsQuery);
|
||||||
|
$stmt->bindValue(":SID", $id);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
16
homework/2/counterDB/impl/queries.php
Normal file
16
homework/2/counterDB/impl/queries.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
$getHitsQuery = "
|
||||||
|
SELECT
|
||||||
|
hits
|
||||||
|
FROM
|
||||||
|
Counter
|
||||||
|
WHERE
|
||||||
|
siteID LIKE :SID";
|
||||||
|
|
||||||
|
$setHitsQuery = "
|
||||||
|
INSERT INTO
|
||||||
|
Counter(siteID, hits)
|
||||||
|
VALUES
|
||||||
|
(:SID, 1)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
hits = hits + 1";
|
||||||
21
homework/2/counterDB/index.php
Normal file
21
homework/2/counterDB/index.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<?php include_once "../../../base/meta.php" ?>
|
||||||
|
|
||||||
|
<title>Counter DB Tester</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
// PHP
|
||||||
|
include_once "../../../base/headers.php";
|
||||||
|
Headers::html();
|
||||||
|
?>
|
||||||
|
This is a dummy test for the database Counter
|
||||||
|
|
||||||
|
<?php include_once "./counter.php" ?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user