Is it possible to validate id of a get without javascript?

Asked

Viewed 116 times

1

I would like to validate the GET id 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); 

?>
  • Yes it is possible, believe me. If you come by GET check first if the key exists with isset() then see if the given value is a valid number, can be done with a cast or ctype_digit().

  • The problem is you can’t get the id of the link?

  • yes @rray , I was following a tutorial, and in this tutorial get was validated with js . attr('post') but I want to validate with php

  • Good afternoon, I don’t see any javascript where you wrote /*com javascript*/, could be clearer? What exactly does javascript have to do with this?

  • because in javascript has the . attr('post') validating a $_post if I were to put the js would be very extensive @Guilherme Nascimento

  • Sorry, this is not specified in the body of the question, we highly recommend you read this link: http://answall.com/help/mcve

  • @Guilherme Nascimento will not read , I’m in the stack since 2014 I know the rules , the array answered my question, ok thanks

  • All right, no need to read, your question presents nothing about the use of attr() inside the body, this makes it very difficult to help, I’m glad @rray helped you and at the same time sad that unfortunately you do not accept well constructive criticism (nay I am talking about the link). I myself am here since 2014 and I attend every day and still make some mistakes, it is normal.

  • turns out that I asked the question by cel @Guilherme Nascimento , I’m beginner in phpoo , I thought cool your initiative understand I mentioned javascript in the question without being in the code I saw a tutorial that validates a get with js , I wanted to do the opposite

  • 3

    Friend, regardless of being php, java, c#, javascript, mysql, html or anything the problem is with the question asked, lacked details, just this, I’m just guiding you, so that in the next questions you can better convey the problem and with details, facilitating the side of who will answer, today fortunately there was a user ( @rray) with good will and interest in answering, but it is not always so when the question has no details or is a little confused. I hope you don’t mind. See you later.

Show 5 more comments

1 answer

3

When sending GET requests, parameters and values should be sent by the url, the attribute is useless id of html tags.

Modify your link to:

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

You can do a preliminary test to see if the name of the Internet and the value passed is quite 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';
}
  • Do you remember the problem I was having with unlink? It deletes the BD img and the folder the problem is that it erases all img , so I asked this question , I wanted to rename the image link ex: <a id="example-'. $result['id']. ' " href="page.php"> <img src="upload/photo.jpg"></a>

  • If you are going to do php, you need to pass the id by the url, hover over the link, you will see that always the ?id=

  • appeared the id of the photo id=1 will create a variable to validate the photo , I’m afraid the user delete the photo of another ex: site.php? fotoid=1&acao=deletephoto=1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.