brucegm
-
Posts
5 -
Joined
-
Last visited
Never
Posts posted by brucegm
-
-
Hi there
I am trying to use cURL to retrieve XML from a gateway. The code I am using works (ie. returns the HTTP response) for any URL that I use except the one that I need! The URL is below, and when using that I get a blank response every time. I've tested and can telnet to that IP address on that port from my server.
I'm not sure if it is because of the format/structure of the URL? Could it have something to do with the port of the gateway? Any assistance would be much appreciated.
http://196.11.120.190:8080/mtnusa/client.jsp?command=<usareq NODE="tHTTP" USERNAME="HTTP" PASSWORD="1234" TRANSFORM="SMPP"><command><submit_sm><a_number>278200703520709</a_number><b_number>27824411926</b_number><service_type/><message>Test</message><registered_delivery/></submit_sm></command></usareq>
The function I am using (from http://davidwalsh.name) is:
/* gets the data from a URL */
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$returned_content = get_data('http://196.11.120.190:8080/mtnusa/client.jsp?command=<usareq NODE="HTTP" USERNAME="HTTP" PASSWORD="1234" TRANSFORM="SMPP"><command><submit_sm><a_number>278200703520709</a_number><b_number>27824411926</b_number><service_type/><message>Test</message><registered_delivery/></submit_sm></command></usareq>');
-
Thanks! I'm on a steep learning curve this will help.
-
Thanks! It works perfectly. I am a bit out of my depth on this - I am trying to loop through multiple records and pick up a few of the node values. By editing your script I get all the values, but not grouped by record (if that makes sense).
So for example, with this XML:
<root><item><usa_smpp_host>THTTP</usa_smpp_host><source_addr>123456</source_addr>
<short_message>id:660352946 sub:001 dlvrd:001 submit date:1102081032 done date:1102081035 stat:DELIVRD err:000 text:Test SMS message 1</short_message>
<dest_addr_npi>1</dest_addr_npi></item></root>
<root><item><usa_smpp_host>THTTP</usa_smpp_host><source_addr>987654</source_addr>
<short_message>id:660352946 sub:001 dlvrd:001 submit date:1102081032 done date:1102081035 stat:DELIVRD err:000 text:Test SMS message 2</short_message>
<dest_addr_npi>1</dest_addr_npi></item></root>
<root><item><usa_smpp_host>THTTP</usa_smpp_host><source_addr>554647</source_addr>
<short_message>id:660352946 sub:001 dlvrd:001 submit date:1102081032 done date:1102081035 stat:DELIVRD err:000 text:Test SMS message 3</short_message>
<dest_addr_npi>1</dest_addr_npi></item></root>
So I need the source_addr and the text from short_message. By editing your code I got this:
123456
987654
554647
Test SMS message 1
Test SMS message 2
Test SMS message 3
How do I loop through the XML to get the data returned like this:
123456
Test SMS message 1
987654
Test SMS message 2
554647
Test SMS message 3
-
Hi there
I need to extract data from some XML. I have found a few sites that explain that part to me, however there is a section of the data which I need to extract and am not sure how to go about it. Below is an extract of the XML, the section I am trying to extract is highlighted in red (it is essentially a text message being sent I am trying to get the contents of the sms/text message):
<usa_smpp_host>THTTP</usa_smpp_host>
<short_message>id:660352946 sub:001 dlvrd:001 submit date:1102081032 done date:1102081035 stat:DELIVRD err:000 text:Test SMS message</short_message>
<dest_addr_npi>1</dest_addr_npi>
Any assistance would be appreciated. Have played around quite a bit but have not managed to figure it out yet.
thanks
PHP failing to save report with Cron
in PHP Coding Help
Posted
Hi there
I have a PHP file that works perfectly when I run it in my browser (compiles a report and saves it to my server), however when run from Cron gives a totally different output. Below is the code, and below that is the output I get when run from Cron.
<?php
include("db_conn.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Customer Appreciation Project</title>
</head>
<body>
<?php
$date = date("Y-m-d");
$time = date("h:i:s",time());
$file = $date.".html";
$fp=@fopen("active_members/".$file, 'w');
$content = "<html><head><title>Active Members Report</title></head><body>";
$content = $content . "<h1>Active Members</h1>";
$content = $content . "<p><font size=1>Report run on ". $date . " at ". $time."</font></p>";
$fetch_members = mysql_query("SELECT * FROM membership_periods WHERE (membership_periods.Start_Date <= Now() AND membership_periods.End_Date >= Now()) ORDER BY Member_Number");
if (mysql_num_rows($fetch_members) == "0")
{
$content = $content . "<p>No results were found.</p>";
} else {
$content = $content . "<table border=0 cellpadding=2 width=100%>";
$content = $content . "<tr><td><b>Member Number</b></td><td><b>Start Date</b></td><td><b>End Date</b></td><td><b>Affiliation</b></td><td><b>Voucher</b></td></tr>";
while($row = mysql_fetch_array($fetch_members))
{
$content = $content . "<tr><td>". $row['Member_Number'] ."</td><td>". $row['Start_Date']."</td><td>". $row['End_Date'] ."</td>";
$Affiliation_ID = $row['Affiliation_Group_ID'];
if (Affiliation_ID > 0)
{
$fetch_affiliation= mysql_query("SELECT * FROM affiliation_groups WHERE ID = '$Affiliation_ID'");
$Affiliation_Group_Name = mysql_result($fetch_affiliation, 0, "Affiliation_Group_Name");
$content = $content . "<td>". $Affiliation_Group_Name ."</td>";
} else {
$content = $content . "<td> </td>";
}
$Member_Number = $row['Member_Number'];
$fetch_member_id = mysql_query("SELECT ID FROM members WHERE Member_Number = '$Member_Number'");
$Member_ID = mysql_result($fetch_member_id, 0, "ID");
$fetch_voucher = mysql_query("SELECT Voucher_ID FROM reward_assignments WHERE Member_ID = '$Member_ID' AND Reward_Valid_To >= Now()");
if (mysql_num_rows($fetch_voucher) > 0)
{
$Voucher_ID = mysql_result($fetch_voucher, 0, "Voucher_ID");
$fetch_voucher_no = mysql_query("SELECT Voucher_Number FROM reward_vouchers WHERE ID = '$Voucher_ID'");
$Voucher_Number = mysql_result($fetch_voucher_no, 0, "Voucher_Number");
}
$content = $content . "<td>". $Voucher_Number ."</td></tr>";
$Affiliation_Group_Name = "";
$Voucher_Number = "";
}
$content = $content . "</table>";
}
$content = $content . "</body></html>";
fwrite($fp, $content);
fclose($fp);
?>
</body>
</html>
And this is the Output I get mailed to me when Cron job runs:
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Customer Appreciation Project</title>
</head>
<body>
PHP Notice: Use of undefined constant Affiliation_ID - assumed 'Affiliation_ID' in /var/www/reports/active_members.php on line 40
PHP Notice: Undefined variable: Voucher_Number in /var/www/reports/active_members.php on line 63
PHP Notice: Use of undefined constant Affiliation_ID - assumed 'Affiliation_ID' in /var/www/reports/active_members.php on line 40
PHP Notice: Use of undefined constant Affiliation_ID - assumed 'Affiliation_ID' in /var/www/reports/active_members.php on line 40
PHP Notice: Use of undefined constant Affiliation_ID - assumed 'Affiliation_ID' in /var/www/reports/active_members.php on line 40
PHP Notice: Use of undefined constant Affiliation_ID - assumed 'Affiliation_ID' in /var/www/reports/active_members.php on line 40
PHP Notice: Use of undefined constant Affiliation_ID - assumed 'Affiliation_ID' in /var/www/reports/active_members.php on line 40
PHP Notice: Use of undefined constant Affiliation_ID - assumed 'Affiliation_ID' in /var/www/reports/active_members.php on line 40
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/reports/active_members.php on line 75
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/reports/active_members.php on line 76
</body>
</html>
Any assistance would be much appreciated.