Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts

    php -post to another site

    I want to from my php code hit another server with a post request (not get/querysting) --
    can i do this?

    I basically have a form that I need to post to php for validation but then i want to send to a different post page (with all of the same values retreived from the form) and then when the post is sent successfully redirect to my success page.

    can someone advise me the best way to do this?

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by esthera View Post
    I want to from my php code hit another server with a post request (not get/querysting) --
    can i do this?

    I basically have a form that I need to post to php for validation but then i want to send to a different post page (with all of the same values retreived from the form) and then when the post is sent successfully redirect to my success page.

    can someone advise me the best way to do this?
    If you don't just mean setting the form to method=POST and the action to another website then I think it would be best through perl. But I may be wrong. I don't really know how to do it, but that might be a better question to ask.

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts
    no i don't want to do it with the post as it will be after the form is submitted.
    I know in asp I would do it as follows:

    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.open "POST", url, false
    xmlhttp.send ""
    tresponse= xmlhttp.responseText
    set xmlhttp = nothing


    also is there anyway to pull all the variables from teh post and put it in a string (like with a querysting)

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You'd want curl (i said perl before, oops ) to do it then.

    Something along these lines would do the trick...

    PHP Code:
    $xmlRequest "<remoteform>".
                    
    "<name>".htmlentities$_POST['name'] )."</name>".
                    
    "<password>".htmlentities$password)."</password>".
                    
    "</remoteform>";

    /* Use CURL to execute XML POST and write output into a string */
            
    $ch curl_init$myURL );
            
    curl_setopt$chCURLOPT_POST);
            
    curl_setopt$chCURLOPT_POSTFIELDS$xmlRequest );
            
    curl_setopt$chCURLOPT_RETURNTRANSFER);
            
    curl_setopt$chCURLOPT_TIMEOUT240 );
            
    $xmlResponse curl_exec$ch ); 
    Something like that, read up at http://php.net/manual/en/ref.curl.php for more info on what that all does.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •