Link to home
Start Free TrialLog in
Avatar of Whisky
Whisky

asked on

Form post to two different sites with curl

Hi,

following problem is bugging me for some time now.

I would like to post data to two sites (one is mine (thats all clear) and another is .asp web server (have no control over it)).

My design looks like this:
a.php (form post) --> b.php (all vars are inserted to my database) --> c.asp (foreign site) --> d.asp(foreign site)

I'm trying with Curl to post vars from b.php to c.asp.
Main problems are ...
... when foreign site receives data from <c.php>, goes to <d.asp> and adds id=xxxx in url, which I also need to store in my database
... when Id is saved, more data (allways the same values) must send to d.asp to complete signup.

Did anyone try something like that (some example perhaps), Examples I saw can not read vars from url, and some other problems.

Regards ...

my b.php file looks like this
// ---- start -------------------------------------------
        $postfields = array();
        $postfields[] = array("znamka", 'Audi');
        $postfields[] = array("model", '80');
        $postfields[] = array("tip", 'elite');
        $postfields[] = array("letnik", '1980');
        $postfields[] = array("modelnoleto", '1981');
         
        foreach($postfields as $subarray) {
             list($foo, $bar) = $subarray;
             $bar = urlencode($bar);
             $postedfields[]  = "$foo=$bar";
        }
         
        $urlstring = join("\n", $postedfields);
        $urlstring = ereg_replace("\n", "&", $urlstring);
        echo $urlstring;
                                          
        $ch = curl_init("http://www.somesite.com/c.asp");
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $urlstring);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ch, CURLOPT_REFERER, "http://www.somesite.com/x.asp");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($ch);
        curl_close($ch);

// ------------- end sending data ---------------

/*  missing part

Problem Geting back ID from url here
and posting some more data to d.asp

*/
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial