We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Yahoo search marking API examples with php-4.3.11

mit1290
mit1290 asked
on
Medium Priority
385 Views
Last Modified: 2014-11-12
I am looking for some good examples using ysm API that are compatible with php4. I found one sample script but it uses DOM which won’t work with anything less than PHP5 and I am not ready to upgrade yet so I need to find another example that will work with my version of PHP.

sample.php

<?php

$USERNAME   = $_SERVER[''];
$PASSWORD   = $_SERVER[''];
$KEY        = $_SERVER[''];
$ACCOUNT_ID = $_SERVER[''];

$host = "x-secure-test.overture.com";
$url = "https://$host/index.jhtml?_DARGS=/index.jhtml";

$dom = new DOMDocument('1.0', 'utf-8');

// DTCRequest tag
$temp = $dom->CreateElement('DTCRequest');
$temp->setAttribute('username', $USERNAME);
$temp->setAttribute('password', $PASSWORD);
$temp->setAttribute('key',      $KEY);
$temp->setAttribute('xmlns',    'urn:/ows/aws/1.2');
$temp->setAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema-instance');
$temp->setAttribute('xs:schemaLocation', "urn:/ows/aws/1.2 https://$host/schema/dtc/1.2/dtc_request.xsd");
$req_root = $dom->appendChild($temp);

# Actions tag
$temp = $dom->createElement('Actions');
$temp->setAttribute('accountId', $ACCOUNT_ID);
$action_root = $req_root->appendChild($temp);

// *the* action
$temp = $dom->createElement('GetAccountBalance');
$action_root->appendChild($temp);

$the_xml = $dom->saveXML();
?>

XML Request:<br />
<textarea cols="80" rows="15">
<?= $the_xml ?>
</textarea>
<br />

<?php

$request = array();
$request['xml'] = urlencode($the_xml);
$request['_D:/go2/xml/XMLRequestHandler.submit='] = '';
$request_str = "";
foreach ($request as $k=>$v) {
    $request_str .= "$k=".utf8_encode($v)."&";
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_str);

$data = curl_exec($ch);
if (curl_errno($ch)) {
    print curl_error($ch);
    exit;
}
curl_close($ch);

?>

XML Response:<br />
<textarea cols="80" rows="15">
<?= $data ?>
</textarea>
Comment
Watch Question

Commented:
Hi,

Well is your server has the domxml extenssion enabled?

if there is you can use DOMXML instead of DOM.

Commented:
if you have it an exmple is something like this

<?php

$USERNAME   = $_SERVER[''];
$PASSWORD   = $_SERVER[''];
$KEY        = $_SERVER[''];
$ACCOUNT_ID = $_SERVER[''];

$host = "x-secure-test.overture.com";
$url = "https://$host/index.jhtml?_DARGS=/index.jhtml";

//$dom = new DOMDocument('1.0', 'utf-8');
$dom = domxml_new_doc('1.0');

// DTCRequest tag
//$temp = $dom->CreateElement('DTCRequest');
$temp = $dom->new_child('DTCRequest');
print_r($temp);
//$temp->setAttribute('username', $USERNAME);
$temp->set_attribute('username', $USERNAME);
//$temp->setAttribute('password', $PASSWORD);
$temp->set_attribute('password', $PASSWORD);
//$temp->setAttribute('key',      $KEY);
$temp->set_attribute('key', $KEY);
//$temp->setAttribute('xmlns',    'urn:/ows/aws/1.2');
$temp->set_attribute('xmlns', 'urn:/ows/aws/1.2');
//$temp->setAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema-instance');
$temp->set_attribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema-instance');
//$temp->setAttribute('xs:schemaLocation', "urn:/ows/aws/1.2 https://$host/schema/dtc/1.2/dtc_request.xsd");
$temp->set_attribute('xs:schemaLocation', "urn:/ows/aws/1.2 https://$host/schema/dtc/1.2/dtc_request.xsd");
$req_root = $dom->append_child($temp);


# Actions tag
$temp = $dom->create_element('Actions');
$temp->set_attribute('accountId', $ACCOUNT_ID);
$action_root = $req_root->append_child($temp);

// *the* action
$temp = $dom->create_element('GetAccountBalance');
$action_root->append_child($temp);

$the_xml = $dom->dump_mem();
?>

XML Request:<br />
<textarea cols="80" rows="15">
<?= $the_xml ?>
</textarea>
<br />

<?php

$request = array();
$request['xml'] = urlencode($the_xml);
$request['_D:/go2/xml/XMLRequestHandler.submit='] = '';
$request_str = "";
foreach ($request as $k=>$v) {
    $request_str .= "$k=".utf8_encode($v)."&";
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_str);

$data = curl_exec($ch);
if (curl_errno($ch)) {
    print curl_error($ch);
    exit;
}
curl_close($ch);

?>

XML Response:<br />
<textarea cols="80" rows="15">
<?= $data ?>
</textarea>

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Worked great. Thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.