Is there a way to use GET and POST together?

I need to pass some data along with these two methods (GET AND POST). I am writing this method, but I do not know if this is safe:

<form method="post" action="profile.php?id=<?php echo $_SESSION['id']; ?>" enctype="multipart/form-data">
<input type="text" size="40" name="title" >
<textarea name="description" rows="2" cols="30"></textarea>
<input id="starit" name="submit" value="Create" type="submit" />
</form>

<?php 
a= $_GET['id'];
b= $_POST['title'];
c= $_POST['description'];
?>

Is this code safe? Or are there other ways to do this?

+5
source share
4 answers

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

What you wrote will be correct. Always make sure you get the expected fields:

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

Btw, make sure you avoid exiting:

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

And if you do not download files, you do not need to install enctypeyours <form>.

+11
source

This is better:

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

REQUEST GET POST params, "-" GET, POST .

http://php.net/request-order

php.ini

+1
source

do not write the method attribute to the form state and add the formmethod = "" attribute to the input ... for example:

<input type="submit" formmethod="get"  name="inputGet" value="updateGet" >
<input type="submit" formmethod="post" name="inputPost" value="updatePost" >
-1
source

All Articles