I have written a supersimple code to track my blog's activity. I'm including this file on every page at the very begining:
<?php
session_start();
if ($_SESSION["i"] == "") {
$_SESSION["i"] = rand(0,9) . chr(rand(65,90)) . chr(rand(65,90)) . chr(rand(65,90));
}
$r = $_SERVER['HTTP_REFERER'];
if ($r == "") {$r = "Direct";}
$u = $_SERVER['REQUEST_URI'];
include ($_SERVER['DOCUMENT_ROOT'].'/db.php');
$stmt = $conn->prepare("INSERT INTO analytika (id, page, referrer, visit, time) VALUES (DEFAULT, ?, ?, ?, DEFAULT)");
$stmt->bind_param("sss",$u,$r,$_SESSION["i"]);
$stmt->execute();
$stmt->close();
$conn->close();
?>
Problem is, what do I do to prevent echo's from PHP when error occures?
I've found error_reporting(0); but that obviously isn't the solution, because my page wont load further the error. And since im including things into DB, problems may really occur.
So, how do I rewrite my code to skip itself if something goes wrong and the page loads on as it would normally? Thanks PHP 7.0