Hello,
I know the safest way to write a pagination section with php is to use the http_build_query().
Like so:
$i = 0;
while($i<$total_pages)
{
$i++;
if($_GET['bool']=='null')
{
//Page Format: $_GET List.
$array = array("tbl"=>"$tbl","col_1"=>"$col_1","bool"=>"$bool","input_1"=>"$input_1","lmt"=>"$limit","pg"=>"$i");
}
else
{
//Page Format: $_GET List.
$array = array("tbl"=>"$tbl","col_1"=>"$col_1","col_2"=>"$col_2","bool"=>"$bool","input_1"=>"$input_1","input_2"=>"$input_2","lmt"=>"$limit","pg"=>"$i");
}
$serps_url = $_SERVER['PHP_SELF'].'?'.http_build_query($array);
if($i==$page)
{
echo '<a href="' .htmlspecialchars($serps_url) .'">' ."<b>$i</b>" .'</a>';
}
else
{
echo '<a href="' .htmlspecialchars($serps_url) .'">' ."$i" .'</a>';
}
}
I believe the above code is buggy because there is no need to use the htmlspecialchars() here.
Am I correct ?
Is the following code ok or not ?
$i = 0;
while($i<$total_pages)
{
$i++;
if($_GET['bool']=='null')
{
//Page Format: $_GET List.
$array = array("tbl"=>"$tbl","col_1"=>"$col_1","bool"=>"$bool","input_1"=>"$input_1","lmt"=>"$limit","pg"=>"$i");
}
else
{
//Page Format: $_GET List.
$array = array("tbl"=>"$tbl","col_1"=>"$col_1","col_2"=>"$col_2","bool"=>"$bool","input_1"=>"$input_1","input_2"=>"$input_2","lmt"=>"$limit","pg"=>"$i");
}
$serps_url = $_SERVER['PHP_SELF'].'?'.http_build_query($array);
if($i==$page)
{
echo '<a href="' .$serps_url .'">' ."<b>$i</b>" .'</a>';
}
else
{
echo '<a href="' .$serps_url .'">' ."$i" .'</a>';
}
}
Page Format 1: https://localhost/Work/buzz/Templates/Pagination_TEMPLATE.php?tbl=links&bool=null&col_1=domain&input_1=brute.com&lmt=1&pg=1