Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Form post to two different sites with curl

Posted on 2004-09-22
4
Medium Priority
?
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

648 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