Sorry if the title of the question is too bad, i'm new on php and i don't know if there's a specific name for this.
I have only to 2 records and i limited the pagination to show only 1 records per page, then I will have 2 pages, and I can access these pages with &tab=1 and &tab=2, on my current code if i write on the URL: &tab=-2, &tab=-1, &tab=0, &tab=3, &tab=4, &tab=5 I can go to that page, and on that page I will see none records because as i said i have only 2 pages.
My questions:
1. There's any security issues on it?
2. How to don't allow the user to go further the existing pages?
This is my pagination code:
<?php
if(empty($_GET['tab'])){}else{$page = $_GET['tab'];}
if(isset($page)){$page = $_GET['tab'];}else{$page = 1;}
$maximoVEP = 1;
$startVEP = (($maximoVEP * $page) - $maximoVEP);
$title = 'Asic';
$stmtVEP = $db->prepare("SELECT count(*) FROM table WHERE data = 'vm' AND title = :title");
$stmtVEP->bindValue(':title', $title, PDO::PARAM_STR);
$stmtVEP->execute();
$total = $stmtVEP->fetchColumn();
$total_pages = ceil($total/$maximoVEP);
echo '<nav aria-label="Page navigation example">';
echo '<ul class="pagination paginationEp ml-1 mr-1">';
if ($page >= 2){
echo '<li class="page-item">';
echo '<a class="page-link" href="?p=';
echo htmlentities($slug, \ENT_QUOTES, "UTF-8", false);
echo '&tab='.($page-1).'"><i class="fas fa-angle-left"></i> ANTERIOR</a>';
echo '</li>';
}
echo '<li class="page-item">';
echo '<a class="page-link" href="';
echo htmlentities($slug, \ENT_QUOTES, "UTF-8", false);
echo '"><i class="fas fa-list-ul"></i></i></a>';
echo '</li>';
if ($page < $total_pages){
echo '<li class="page-item">';
echo '<a class="page-link" href="?p=';
echo htmlentities($slug, \ENT_QUOTES, "UTF-8", false);
echo '&tab='.($page+1).'">PRÓXIMO <i class="fas fa-angle-right"></i></a>';
echo '</li>';
}
echo '</nav>';
$conn = null;
?>
And the query:
$stmtUTP = $db->prepare("SELECT `id`, `title` FROM table WHERE data = 'vm' ORDER BY id DESC LIMIT :start, :max");
$stmtUTP->bindValue(':start', $startVEP, PDO::PARAM_INT);
$stmtUTP->bindValue(':max', $maximoVEP, PDO::PARAM_INT);
$stmtUTP->execute();