CrazyEngineers
  • How to Post variables to url using function in php?

    Manish Goyal

    Manish Goyal

    @manish-r2Hoep
    Updated: Oct 22, 2024
    Views: 1.3K
    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?
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • PraveenKumar Purushothaman

    MemberApr 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);
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberApr 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... 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Prasad Ajinkya

    MemberApr 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.
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberApr 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... 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberApr 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
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register