1

After reading:

I understand, that GET is used to retrieve a page without changing the server and POST is used for things (insert, update, delete), that change the server.

Now I have written a page which is called with a GET request with parameter StationNr set. The user can fill a form and makes a POST request to the same page with parameter Filter set. But I don't want to miss the parameter StationNr thus I thought I give it into a hidden input field. But then the parameter StationNr is either in the $_GET variable (first call) or in the $_POST variable (second call). I can do something like:

if (isset($_GET['StationNr']))
    $snr = $_GET['StationNr'];
else if (isset($_POST['StationNr']))
    $nr = $_POST['StationNr'];

But I don't like this. Also I don't want to use $_REQUEST['StationNr'] because of: When and why should $_REQUEST be used instead of $_GET / $_POST / $_COOKIE?

I think this is a common issue but I haven't faced it yet because I'm a beginner in writing php pages. How did you solve this problem?

Thanks!

2
  • It might not be the cleanest design, put you can certainly fire a POST request to an address to which you append a ?param=value&... string to have both GET and POST.
    – Kerrek SB
    Jul 2, 2011 at 20:58
  • The $_REQUEST badmouthing is unwarranted. With older setups it was subject to cookie fixation, which is often a usability, but not a security issue. Nevertheless it's intended as shortcut for exactly that (GET/POST input parameters as aliases).
    – mario
    Jul 2, 2011 at 21:19

3 Answers 3

3

Although you can use ?foo=bar to push GET values in a POST request, I'd suggest checking the request method instead:

if($_SERVER['REQUEST_METHOD'] == 'POST') { ... }
1

just use

<form method="post" action="script.php?get=variables">
 <input name="your_inputs" />
</form>
1
  • Ahh I see, I gave me this answer with a link in my question :-) Consequently the page is requested by a POST but I can also query the $_GET variables? Jul 2, 2011 at 21:10
-2

Correct Syntax Would Be:

if (isset($_GET['StationNr'])) {   
$snr = $_GET['StationNr'];
}else if (isset($_POST['StationNr']))    
$nr = $_POST['StationNr']; 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.