oz11's post in Only shows on second refresh..? was marked as the answer
July 14, 2023
Fixed code:
<?php
include 'config.php';
$stmt = $pdo->prepare("SELECT count(*) FROM news WHERE reference=?");
$stmt->execute([$_GET['ref']]);
$check_exist = $stmt->fetchColumn();
if($check_exist == 0){
echo "error not found";
exit();
}
$user_ip=$_SERVER['REMOTE_ADDR'];
$stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE IP = ? AND news_reff = ?");
$stmt->execute([$user_ip, $_GET['ref']]);
$count = $stmt->fetchColumn();
if($count == 0){
$sql = "INSERT INTO outgoing_count (IP, news_reff) VALUES (?,?)";
$stmt= $pdo->prepare($sql);
$stmt->execute([$user_ip, $_GET['ref']]);
$stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE news_reff = ?");
$stmt->execute([ $_GET['ref']]);
$count2 = $stmt->fetchColumn();
echo "Redirect. This page has been viewed ".$count2."times";
} else {
$stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE news_reff = ?");
$stmt->execute([$_GET['ref']]);
$count3 = $stmt->fetchColumn();
echo "Redirect. This page has been viewed ".$count3."times";
//header('Location: http://google.com');
}
?>
.. just needed time.