/    Sign up×
Community /Pin to ProfileBookmark

PHP cURL problem

Bare with me while I try to explain my problem. First I have a client that wants to track all the searches on his site for a English to Turkish translator. However the translator is located at:
[url]http://www.trengle.com/page-en-tool-v1b.asp[/url]

Basically it loads an <iFrame> on the client’s page and displays information using AJAX. Now the javascript calls:
[url]http://www.trengle.com/MTrengle/mini_xx_trengle_dictman.asp[/url]

using the XMLHttpRequest() method to return XML to JavaScript for parsing and displaying. Now I know that you can’t use this method across domains so I can just post to this site using the method and get back any XML

What I tried instead was setting up a PHP proxy to cURL the page, get the XML and then I can do with it what I please. However, when I cURL the page, I get absolutely no results, not even an error. My code for the proxy is below:

<?php
// Open the Curl session
$session = curl_init();

// Put the POST data in the body
$postvars = “fLang=EN&fReq=ET&fType=EXACT&fText=Hello&Submit=Submit”;
curl_setopt($session, CURLOPT_URL, “http://www.trengle.com/MTrengle/mini_xx_trengle_dictman.asp“);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the call
$xml = curl_exec($session);

// The web service returns XML. Set the Content-Type appropriately
header(“Content-Type: text/xml”);

echo $xml;
curl_close($session);
?>

Right now I am not even collecting the POST variables, I am just setting it to a string to get some results back, yet nothing has worked. If you go to:
[url]http://barleyct.freetzi.com/poster.html[/url]

You will see what the function is suppose to produce. Any help would be greatly appreciated as I am at a loss.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@TecBratMar 09.2008 — I uploaded your code to my server and it gave this result:[code=html]<?xml version="1.0"?>
<m_seg><m_seg_t type="m_res"><dlh><dtr>1</dtr><drq>ET</drq><dtx>Hello</dtx></dlh><dlb><dr><da>hello</da><db>merhaba</db></dr></dlb></m_seg_t></m_seg>
[/code]


I hope this is helpful.
Copy linkTweet thisAlerts:
@BarleyauthorMar 09.2008 — Thanks for the info. I thought my code was sound, there must be a problem with the cURL installation on the server I am using.

Anyone know why it is hard to find a web hosting provider that provides cURL with their PHP package? Is it that insecure?
Copy linkTweet thisAlerts:
@BarleyauthorMar 11.2008 — Ahhh, the client's web server is a beauty. It is currently running PHP 4 so I cannot easily parse the XML I am given using the SimpleXML extension. I have a XML parser class that takes the given XML and puts it into an associative array. After plugging it into my code, I get the array below. I however am horrible in dealing with arrays and have no idea how to call the "DB" XML element I am needing. Anyone know how to get the value for this specific tag?

Edit: I couldn't get the whitespace to appear correctly on the forum, so if you go here: http://www.ingilizce.com/trengle/update_dbase.php, it will display the array in question. Just click "View Source" in your browser and the whitespace will appear to make it easier on your eyes.

xmlparser Object

(

[xml_obj] => Resource id #3

[output] => Array

(

[0] => Array

(

[name] => M_SEG

[child] => Array

(

[0] => Array

(

[name] => M_SEG_T

[attrs] => Array

(

[TYPE] => m_res

)

[child] => Array
(
[0] => Array
(
[name] => DLH
[child] => Array
(
[0] => Array
(
[name] => DTR
[content] => 1
)

[1] => Array
(
[name] => DRQ
[content] => ET
)

[2] => Array
(
[name] => DTX
[content] => Hello
)

)

)

[1] => Array
(
[name] => DLB
[child] => Array
(
[0] => Array
(
[name] => DR
[child] => Array
(
[0] => Array
(
[name] => DA
[content] => hello
)

[1] => Array
(
[name] => DB
[content] => merhaba
)

)

)

)

)

)

)

)

)

)

[attrs] =>

)
×

Success!

Help @Barley spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...