Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Form post to two different sites with curl

Posted on 2004-09-22
4
Medium Priority
?
261 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
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 1000 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 1000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

810 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