How to Post variables to url using function in php?

Manish Goyal

Manish Goyal

@manish-r2Hoep Oct 22, 2024
I have a problem in php
basically if we want to pass post variable to a url using php we add

<form action="url">
</form>

But i want to pass it to url using function

for eg

function manish($_POST)
{
$url="https://example.com?";
$url.=$url.$_POST;
}

any idea how to do this?

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 Apr 12, 2011

    You cannot pass it using a function. But you can do so using headers...
    $host "www.example.com";
    $path "/path/to/script.php";
    $data "data1=value1&data2=value2";
    $data urlencode($data);

    header("POST $path HTTP/1.1\r\n");
    header("Host: $host\r\n");
    header("Content-type: application/x-www-form-urlencoded\r\n");
    header("Content-length: " strlen($data) . "\r\n");
    header("Connection: close\r\n\r\n");
    header($data);
  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 Apr 13, 2011

    You can also use CURL to post the data and get the response back, either in a variable or in the output buffer... 😀
  • Prasad Ajinkya

    Prasad Ajinkya

    @prasad-aSUfhP Apr 15, 2011

    A simpler method would be to say method="GET" in your form tag. That way all the form inputs would be submitted as a GET and not as a POST.

    A more tedious approach to this would be to take the variables, encode them and then put that in the URL.
  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 Apr 15, 2011

    kidakaka
    A simpler method would be to say method="GET" in your form tag. That way all the form inputs would be submitted as a GET and not as a POST.

    A more tedious approach to this would be to take the variables, encode them and then put that in the URL.
    Dude, both are simpler... What he is asking is, without a client side interaction, he wants to post the data to another URL got it??? Even I had a same problem but I used header post... 😀
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Apr 15, 2011

    kidakaka
    A simpler method would be to say method="GET" in your form tag. That way all the form inputs would be submitted as a GET and not as a POST.

    A more tedious approach to this would be to take the variables, encode them and then put that in the URL.
    Yes you are right ,but what i want to do is to pass variables to some url which user can' find to which page variables have been passed

    Anyway it has been done now with the use of curl