I'm trying to adapt the relative links to absolutes in my paging script. However, whenever I try to go back or forward a page, the link looks like this:
http://localhost/textos?pag=2?pag=3
Script:
<?php
$url = $_SERVER['SERVER_NAME'];
$urlEndereco = $_SERVER ['REQUEST_URI'];
?>
<table border="1">
<tr>
<?php
if($pag!=1){
echo "<td><a href='http://".$url.$urlEndereco."?pag=".($pag-1)."'> Página Anterior</a></td>";
}
if($contador<=$maximo){
echo "<td>Existe apenas uma única página</td>";
}
else{
for($i=1;$i<=$paginas;$i++){
if($pag==$i){
echo "<td style='background: red'><a href='http://".$url.$urlEndereco."?pag=".$i."'> ".$i."</a></td>";
}else{
echo "<td><a href='http://".$url.$urlEndereco."?pag=".$i."'> ".$i."</a></td>";
}
}
}
if($pag!=$paginas){
echo "<td><a href='http://".$url.$urlEndereco."?pag=".($pag+1)."'> Próxima Página</a></td>";
}
?>
</tr>
</table>
However, if I use the code below, it works normally. But I happen to use pagination with an include on several pages to leave the code clean, having an easier control.
echo "<td><a href='textos?pag=".($pag+1)."'> Próxima Página</a></td>";
I also noticed that $ urlEndereco is causing this, since it does $_SERVER['REQUEST_URI'];
, always returning the end of url: http://localhost/textos?pag=2?pag=3