2012-06-11 9 views
5

Ho bisogno di passare alcuni dati con questi 2 metodi insieme (GET AND POST). Scrivo questo metodo, ma non so se è sicuro:C'è un modo per utilizzare GET e POST insieme?

<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']; 
?> 

È questo il codice di sicurezza? O ci sono altri modi per farlo?

+3

Perché non scrivi solo l'ID sessione in un campo di input nascosto del modulo? Alla fine l'utente può leggere il suo ID di sessione in ogni caso se naviga nella fonte del sito. – Corsair

+0

Forse ha delle ragioni per farlo in questo modo. – Aelios

risposta

11

Questa non è una richiesta GET e POST combinata; piuttosto, è una richiesta POST con parametri di query.

Quello che hai scritto sarebbe stato il modo giusto. Assicurarsi sempre di ottenere i campi previsti:

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

Btw, assicurarsi che si sfuggire l'output:

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

E se non stai caricando file, non è necessario impostare il enctype del tuo <form>.

+0

Oh, puoi usare più variabili con 'isset'? : D – ADTC

+0

@ADTC sì, restituisce vero è tutto impostato –

1

questo è meglio:

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

è possibile utilizzare entrambi e ottenere con richiesta invece di GET o POST, con lo stesso nome di params otterrà l'ordine "richiesta-ordine" GET e poi POST predefinito.

http://php.net/request-order

è nel php.ini

-1

non scrivere attributo metodo nella condizione di forma e aggiungere formmethod ="" l'attributo in ingresso ... ad esempio:

<input type="submit" formmethod="get" name="inputGet" value="updateGet" > 
<input type="submit" formmethod="post" name="inputPost" value="updatePost" > 
+0

intendi "metodo form"? –

+0

sì, non utilizzare il metodo nel tag modulo –