Is there a way to use GET and POST together?

后端 未结 4 1473
时光取名叫无心
时光取名叫无心 2021-01-02 07:59

I need to pass some data with these 2 methods together ( GET AND POST ). I write this method, but I don\'t know if it is safe:

相关标签:
4条回答
  • 2021-01-02 08:19

    don't write method attribute in your form condition and add formmethod=" " attribute in input... for example:

    <input type="submit" formmethod="get"  name="inputGet" value="updateGet" >
    <input type="submit" formmethod="post" name="inputPost" value="updatePost" >
    
    0 讨论(0)
  • 2021-01-02 08:21

    you can use both and get with REQUEST instead of GET or POST, with the same name of params it will get the "request-order" order GET and then POST by default.

    http://php.net/request-order

    it is in php.ini

    0 讨论(0)
  • 2021-01-02 08:32

    This is better :

    <form method="post" action="profile.php?id=<?php echo urlencode($_SESSION['id'])); ?>">
    
    0 讨论(0)
  • 2021-01-02 08:41

    This is not a combined GET and POST request; rather, it's a POST request with query parameters.

    What you have written would be the right way. Always make sure that you get the expected fields:

    if (isset($_GET['id'], $_POST['title'], $_POST['description']) {
      // go ahead
    }
    

    Btw, make sure that you escape your output:

    <form method="post" action="profile.php?id=<?php echo rawurlencode($_SESSION['id']); ?>">
    

    And if you're not uploading files, you don't need to set the enctype of your <form>.

    0 讨论(0)
提交回复
热议问题