OK, Figured it out

This was not formally a prototype issue, but many others of you may
want to do cross browser requests inside prototype and it does work.
For just bringing up page content from other servers is no problem
using the program in my original post and the cURL library (this whole
thing is php-related, but I assume there are similar ways to do this
in other server languages).  Posting data led to a small problem for
me in that I could not use the usual $x=$_POST['name']; in the remote
program.  Rather than a posting array, the proxy program builds a
posting string.  So the remote program must pick up the string, then
spit by '&' and split each of those by '=' to get (for me) an array of
parm names and parm values.  Easy to then compare parm names to
originally expected posting variable names and thus assign values
appropriately.  Thus my example of obtaining posted values in the
remote server prog is:

$pname= array();
$pvalue = array();
$post_data = $HTTP_RAW_POST_DATA;
$split = explode("&", $post_data);
$numparm = count($split);
for ($i=0;$i<$numparm;$i++) {
        $parms = explode("=", $split[$i]);
        $pname[$i] = $parms[0];
        $pvalue[$i] = $parms[1];
}
for ($i = 0; $i < $numparm;$i++) {
        if ($pname[$i] == 'floorfield') $searchfloor = $pvalue[$i];
        if ($pname[$i] == 'cntry-city-bldg') $searchbuild = $pvalue[$i];
        if ($pname[$i] == 'rowfield') $searchrow = $pvalue[$i];
        if ($pname[$i] == 'cabfield') $searchcab = $pvalue[$i];
}

Ben

On Mar 25, 1:45 pm, Bhudda Ben <benjamin.rud...@gmail.com> wrote:
> Hi
>
> First let me say that this is a great group with lots of willing
> responders.  As a newbie to prototype, let me especially send out
> kudos to Quleczka who was very patient with my form serialization/
> processing needs.
>
> Now another form processing problem dealing with cross server
> requests.  I downloaded the following from the web (couple of
> commented lines indicate what I changed/added; I named it
> rawproxy.php) and also installed the cURL library to my php build last
> evening:
>
> <?php
> if (!isset($HTTP_RAW_POST_DATA))   // this line and next were not in
> download, but found a comment that said to add these when
> $HTTP_RAW_POST_DATA was undefined, which it was
>    $HTTP_RAW_POST_DATA = file_get_contents("php://input"); // added
> this with above line
> $post_data = $HTTP_RAW_POST_DATA; // this was here but undefined until
> above added.
> $header[] = "Content-type: text/xml";
> $header[] = "Content-length: ".strlen($post_data);
> $ch = curl_init( $_GET['url'] );
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_TIMEOUT, 10);
> curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
> if ( strlen($post_data)>0 ){
>     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);}
>
> $response = curl_exec($ch);
> if (curl_errno($ch)) {
>     print curl_error($ch);} else {
>
>     curl_close($ch);
>     print $response;}
>
> ?>
>
> I use following observe event all the time for forms even when no
> validation is needed as in this case:
>
> <script>
>         $('formabc').observe ('submit',validatethis);
> </script>
>
> coupled with this no validation script:
>
> <script language="javascript" type="text/javascript">
> validatethis = function(evt)
> {
>         evt.stop();
>         postIt('formabc');}
>
> </script>
>
> and this form:
>
> <form name="formabc" id="formabc" method="post" action="rawproxy.php?
> url=http://dcmweb.mlp.com/machines/DisplayCabinetproxy.php";>
>
> and postIt:
>
> function postIt(theform) {
>         var form = $(theform);
>                 var notice = $("mlprerresult");
>                 var content = $("MiddleContent");
>                 form.request({ onComplete: function(transport) {
>
>                         notice.update('Your request completed successfully');
>                         content.update(transport.responseText);
>
>                 }
>
> });
> }
>
> No problem getting to the remote server (dcmweb), nor coming back and
> displaying transport content - though content itself is in error
> because of numerous errors trying to bring in posted data (as normal
> way of $x=$_POST['field']; - which is probably one form of problem) -
> like (from error_log):
>
> [client 10.77.11.11] PHP Notice:  Undefined index:  floorfield in /dat/
> apacheconf/dcmweb/htdocs/machines/DisplayCabinetproxy.php on line 7
>
> from rawproxy content of $post_data = :
>
> cntry-city-bldg=5&floorfield=08&rowfield=03&cabfield=06 (looks good
> from point of view of names and values))
>
> the same output appears if I use same statements in
> DisplayCabinetproxy and print $post_data; i.e.:
> (if (!isset($HTTP_RAW_POST_DATA))
>    $HTTP_RAW_POST_DATA = file_get_contents("php://input");
> $post_data = $HTTP_RAW_POST_DATA;)
>
> if, however, I use print_r($_POST), I get (in rawproxy):
>
> Array ( [cntry-city-bldg] => 5 [floorfield] => 08 [rowfield] => 03
> [cabfield] => 06 ),
>
> but in DisplayCabinetproxy, I get an empty array.
>
> Ok, I see that the post data is not getting to DisplayCabinetproxy,
> but not sure why; nor what difference is or what I need to do to get
> post data safely to my target or else access what is getting there
> in .
>
> Thanks in advance for going through this long post; hope I have not
> been too gregarious...
>
> Ben
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to