How to convert a POST to a url?

14,344

Solution 1

Firstly you need to know what POST and GET are used for.

  • If you want to SEND data you should use POST

  • If you want to GET data depending on some params then use GET.

There is no sense in sending data with GET there are also some limitations to this. You can read more about limits here.

You can always use CURL to send POST data to the other URL.

Here is good tutorial how to do it and here goes the example based on this tutorial:

<?php
$url = 'http://www.kraljevine.com/Action.php?action=338&n=688&t=mine';
$fields = array(
                    'duree' => urlencode('1'),
                    'travail' => urlencode('submit')
            ); 
//$fields can be extended with more params for POST submit always encode them with urlencode for these 2 examples of 1 submit it is not necessary but sometimes is really imporant to do it

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
?>

The last thing is $_REQUEST which is An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. You can use it in php script and there will be no difference how the variable is passed for php script.

Use it wisely.

Solution 2

The short answer is no.

By definition, GET variables are sent in the URL, and POST variables are sent in the request's body.

So, you can't send your variables JUST by using the URL, as you requested.

You probably can physically catch a possible URL with parameters even in POST request, but I highly recommend you not the takes this approach.

You can read more about it in this post

Solution 3

make the form method GET and put the variables in hidden fields in your form. for example:

<form method="GET" action="Action.php">
 <input type="hidden" name="action" value="338" />
 <input type="hidden" name="n" value="688" />
 <input type="hidden" name="t" value="mime" />
 ...more html/php...
</form>
Share:
14,344

Related videos on Youtube

Crz
Author by

Crz

Updated on July 12, 2022

Comments

  • Crz
    Crz almost 2 years

    Is possible to send data, that you normal have to use a submit button to send it, by using just the url?

    Here is an example of code from a site with a button like that:

    <form method="POST" action="Action.php?action=338&amp;n=688&amp;t=mine"><input type="hidden" id="Mine688" value="1" name="duree"><button value="submit" class="boutonsGeneral" type="submit" name="travail"><span title="" class="infoBoutonsGeneral"><span class="boutonsGeneral_separateur">&nbsp;</span><span class="boutonsGeneral_gain" id="gainMine688"><img width="48" height="24" src="images/items/itemArgent.png">+2,18</span></span>Munca <span class="boutonsGeneral_duree boutonsGeneral_dureeMoins" id="dureeMine688">1 hour</span></button></form>
    

    enter image description here

    This is from Live HTTP Header when I click on that button:

    ww.kraljevine.com/Action.php?action=338&n=688&t=mine
    
    POST /Action.php?action=338&n=688&t=mine HTTP/1.1
    Host: ww.kraljevine.com/
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: ro-ro,ro;q=0.8,en-us;q=0.6,en-gb;q=0.4,en;q=0.2
    Accept-Encoding: gzip, deflate
    Referer: ww.kraljevine.com/EcranPrincipal.php?l=8
    Cookie: PHPSESSID=ec95ed7caf7c28f8a333; KC=account_name; KC2=1502cae30e04f5f55963e93; > > Glup=274; pageTamponVue=1
    Connection: keep-alive
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 22
    duree=1&travail=submit
    

    What I want to do is to send the post by url. Something like:

    http://www.kraljevine.com/Action.php?action=338&n=688&t=mine (untill here is the link from site, and I want to add this) duree=1&travail=submit Is not working http://www.kraljevine.com/Action.php?action=338&n=688&t=mine&duree=1&travail=submit and because of this I am wondering if is possible to do this.