Solved

Form post to two different sites with curl

Posted on 2004-09-22
4
216 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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

728 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

9 Experts available now in Live!

Get 1:1 Help Now