Jump to content

Is cURL the best way to do this?


Robert Heist

Recommended Posts

I am integrating an airline ticket booking engine with a site.  The booking engine provider has set up a search form that we can link to but I want to integrate the search form into our index page.  In order to be able to submit to their results page I have to call their web service and get a 9 digit KeyWords access key to include in the $_POST data but this key expires virtually immediately so it can’t be generated when the index page loads, it has to be generated and appended to the $_POST data when the form is submitted.  In order to accomplish this I have the form submit to a .php page on our server which queries the web service for the key, appends it to the $_POST data and then uses cURL to send it on to their ASP.NET results page.  I am including the code of the .php page for your review.  My question is 2 fold.  The ASP.NET results page is redirecting me to a blank search form as if the proper key or fields weren’t included, but they are because when use cURL to send to a test page on my server I can output all the proper $_POST data.  Is there some cross-domain issue that might cause this?  Second, when cURL redirects, the url remains that of the .php page on my server rather than that of the server hosting the ASP.NET page and this causes problems with links to image files throughout the page.  Is there a way with cURL to make the displayed url change too?

 

You can see the test work at http://laosparadisetravel.com/test/test1.php but it doesn’t work when submitted to the search engine providers page.

 

<?php 
/*
Connect to the web service to get the KeyWords authorization string.
This 9 character string authroizes the submission of the form so must be added to $_POST variables coming from the original form.
Then the new set of $_POST variables are sent to the results page on the service provider's host server.
*/
$params->id="XXXXX";
$params->pwd="XXXXX";
$client = new SoapClient("http://www.bookingenginehost.com/IBEWS.ASMX?WSDL"); 
$result=$client->CheckAndGetKeyWords($params); 
$KeyWords=$result->CheckAndGetKeyWordsResult;

$postData="";
while (list($key,$value) = each($_POST)){$postData .= $key . "=" . $value . "&";}

$len=strlen($postData);
$postData=substr($postData,0,($len-1));

$postData = "KeyWords=" . $KeyWords . "&" . $postData;

$Curl_Session = curl_init('http://laosparadisetravel. bookingenginehost.com/Page/Common/ExternalSearcher.aspx');

// this is the test page that shows that the proper $_POST data is being passed
//$Curl_Session = curl_init('http://www.laosparadisetravel.com/test/test3.php');

curl_setopt ($Curl_Session, CURLOPT_POST, 1);
curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
curl_exec ($Curl_Session);
curl_close ($Curl_Session);

?>

Link to comment
Share on other sites

Well, hand coded a simple AJAX call to set the hidden field KeyWords value to the result of a php soapclient call to the web service.  I am getting a proper key and it is set but unfortunately the destination script still isn't accepting my submission though using AJAX rather than cURL has solved the broken links due to the wrong url issue. 

 

Thanks for your assistance schilly.  Obviously there is something still missing.  Now I guess I need to attempt to get support from the booking engine's coder.  Lot of chance of that.  *sigh*

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.