Is it possible to validate a get id without javascript? [closed]

1

I would like to validate the id of the GET without javascript, only with php. I'm having a hard time.

<a id="exemplo-'.$resultado['id'].' " href="pagina.php"> 

<?php    
/*com javascript*/

 $id = explode('-',$_POST['exemplo']); 
 $ext = end($id);

 /*com O php se valida id assim?*/ 

 $id = explode('-',$_GET['exemplo']);
 $ext = end($id); 

?>
    
asked by anonymous 29.09.2015 / 20:34

1 answer

3

When submitting requests via GET, the parameters and values must be sent by the url, the id of the html tags is useless.

Modify your link to:

<a href="pagina.php?id=<?php echo $resultado['id'];?>">EDITAR</a> 

You can do a preliminary test to know if the index name and past value is very useful, like this:

echo '<pre>';
print_r($_GET); //ou $_POST em outras ocasiões

Validation of id:

if(isset($_GET['id']) && ctype_digit($_GET['id'])){
   echo 'válido';
}else{
   echo 'inválido';
}
    
29.09.2015 / 20:51