Solved

Form post to two different sites with curl

Posted on 2004-09-22
4
236 Views
Last Modified: 2012-11-01
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

*/
0
Comment
Question by:Whisky
4 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 12122293
You can use preg_match to get that id out of the html-code.

if (preg_match('/\bid=(\d+)\b/', $data $m)) {
    echo "id = " . $m[1];
}

For further help the content of $data would be interesting
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 250 total points
ID: 12123063
May I suggest another solution?

I figured you have one page containing the form:

<form method="post" action="myhandler.php"> //or something alike

You could implement an frame/iframe and then submit the form to this frame using target

<iframe name="myiframe"></iframe>
<form method="post" action="myhandler.php" target="myiframe">

You could now have myhandler.php output something like:
<script>
parent.forms[0].target="_self";
parent.forms[0].action="remote_asp.asp";
parent.forms[0].submit();
</script>

Then after the data has been submitted to the frame - the original form still present at the original page - you just tell the original page to resubmit itself, after interpreting the data using your own php.

1.76ct

-r-
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now