recently i upgraded my VPS server so as to increase the ram and storage
After upgrade i noticed that my payment api started giving an error
Error: Illegal characters found in URL
Which i have never encountered before, my API which is used for processing
payments has been running for years and just stopped in march after my upgraded
This is the code am using presently
<?php
/* $myparams = array();
$myparams['subpdtid'] = #### ;
$myparams['submittedref'] = $_SESSION['genref'] ;
$myparams['submittedamt'] = $_SESSION['amt4hash'] ;
$myparams['rettxref'] = $_POST['txnref'] ;
$myparams['retpayRef'] = $_POST['payRef'] ;
$myparams['retretref'] = $_POST['retRef'] ;
$myparams['retcardnum'] = $_POST['cardNum'] ;
$myparams['retappramt'] = $_POST['apprAmt'] ;
$myparams['nhash'] = '########################################################################' ;
*/
$subpdtid = ####; // your product ID
$submittedref = $_POST['tnx_ref']; // unique ref I generated for the trans
$submittedamt = $_POST['amount'];
//$rettxref= $_POST['txnref']; // ref from isw
//$retpayRef=$_POST['payRef']; // pay ref from isw
//$retretref = $_POST['retRef']; // ret ref from isw
//$retcardnum = $_POST['cardNum']; // ret cardnum from isw
//$retappramt = $_POST['apprAmt']; // ret appr amt from isw
$nhash = "04F61D7F7EEE6C80E5D227CA6DAAEA878F46C47B67A9DC7A5A699AD2D13A6249187E85667709F0D978D6697E33817DC771FBA109110ADAD1C4E642D20D439BC2" ; // the mac key sent to you
$hashv = $subpdtid.$submittedref.$nhash; // concatenate the strings for hash again
$thash = hash('sha512',$hashv);
// $credentials = "mithun:mithun";
$parami = array(
"productid"=>$subpdtid,
"transactionreference"=>$submittedref,
"amount"=>$submittedamt
);
$ponmo = http_build_query($parami) . "\n";
//$url = "https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.xml?$ponmo";// xml
$url = "https://webpay.interswitchng.com/paydirect/api/v1/gettransaction.json?$ponmo"; // json
//note the variables appended to the url as get values for these parameters
$headers = array(
"GET /HTTP/1.1",
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1",
//"Content-type: multipart/form-data",
//"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language: en-us,en;q=0.5",
//"Accept-Encoding: gzip,deflate",
//"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"Keep-Alive: 300",
"Connection: keep-alive",
//"Hash:$thash",
"Hash: $thash " );
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,120);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER ,false);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
}
else {
// Show me the result
// $json = simplexml_load_string($data);
$json = json_decode($data, TRUE);
//var_dump($data);
curl_close($ch);
print_r($json);
//echo ($json['ResponseCode']);
//echo ($json['ResponseDescription']);
// loop through the array nicely for your UI
}?>
<?php session_start();
//if(isset($_POST['name'])){
//$amt1 = htmlspecialchars(mysql_real_escape_string($_POST['amount'])) * 100 ;
$desc = $json['ResponseDescription'];
$_SESSION['desc'] = $desc;
$rep = $json['ResponseCode'];
$_SESSION['rep'] = $rep;
$tref = $_POST['tnx_ref'];
$_SESSION['tref'] = $tref;
$amts = $_POST['amount'] /100;
$_SESSION['amount'] = $amts;
//}
?>
<?php echo ($json['ResponseCode']); ?>
<?php echo ($json ->ResponseDescription);?><div align ="center"><h2 style="color:#090" align="center"> <?php echo ($json['ResponseDescription'] ); ?> </h2><br /><img src="wait.gif" width="200" /><div align ="center"><form action="query.php" method="post" name="niid" id="niid"></form><br /></div>
<script type="text/javascript">
window.onload=function(){
window.setTimeout(function() { document.niid.submit(); }, 3000);
};
</script>
<?php } else {?>
<div align ="center"><h2 style="color:#F00" align="center"> Your Transaction Was Not Successfull<br />Reason: <?php echo ($json['ResponseDescription'] ); ?></h2><br /><img src="wait.gif" width="200" /></div>
Please can anyone enlighten me?
It is because you are appending unwanted \n after string
change your code to
$ponmo = http_build_query($parami);
//$url = "https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.xml?$ponmo";// xml
$url = "https://webpay.interswitchng.com/paydirect/api/v1/gettransaction.json?$ponmo"; // json
Related
I have been working on a clients WP site which lists deals from Groupon. I am using the Groupon's official XML feed, importing via WP All Import. This works without much hassle. Now the issue is Groupon doesn't update that feed frequently but some of their deals get sold out or off the market often. So to get this resolved what I am trying is using a CURL script to crawl the links and check if the deal is available or not then turn the unavailable deals to draft posts (Once a day only).
The custom script is working almost perfectly, only after the first 14/24 requests the server starts responding with 502/503 HTTP status codes. To overcome the issue I have used the below precautions -
Using the proper header (captured from the requests made by the browser)
Parsing cookies from response header and sending back.
Using proper referrer and user agent.
Using proxies.
Trying to send request after a set interval. PHP - sleep(5);
Unfortunately, none of this got me the solution I wanted. I am attaching my code and I would like to request your expert insights on the issue, please.
Thanks in advance for your time.
Shahriar
PHP SCRIPT - https://pastebin.com/FF2cNm5q
<?php
// Error supressing and extend maximum execution time
error_reporting(0);
ini_set('max_execution_time', 50000);
// Sitemap URL List
$all_activity_urls = array();
$sitemap_url = array(
'https://www.groupon.de/sitemaps/deals-local0.xml.gz'
);
$cookies = Array();
// looping through sitemap url for scraping activity urls
for ($u = 0; $u < count($sitemap_url); $u++)
{
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0');
curl_setopt($ch1, CURLOPT_REFERER, "https://www.groupon.de/");
curl_setopt($ch1, CURLOPT_TIMEOUT, 40);
// curl_setopt($ch1, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_URL, $sitemap_url[$u]);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, FALSE);
// Parsing Cookie from the response header
curl_setopt($ch1, CURLOPT_HEADERFUNCTION, "curlResponseHeaderCallback");
$activity_url_source = curl_exec($ch1);
$status_code = curl_getinfo($ch1, CURLINFO_HTTP_CODE);
curl_close($ch1);
if ($status_code === 200)
{
// Parsing XML sitemap for activity urls
$activity_url_list = json_decode(json_encode(simplexml_load_string($activity_url_source)));
for ($a = 0; $a < count($activity_url_list->url); $a++)
{
array_push($all_activity_urls, $activity_url_list->url[$a]->loc);
}
}
}
if (count($all_activity_urls) > 0)
{
// URL Loop count
$loop_from = 0;
$loop_to = (count($all_activity_urls) > 0) ? 100 : 0;
// $loop_to = count($all_activity_urls);
$final_data = array();
echo 'script start - ' . date('h:i:s') . "<br>";
for ($u = $loop_from; $u < $loop_to; $u++)
{
//Pull source from webpage
$headers = array(
'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-language: en-US,en;q=0.9,bn-BD;q=0.8,bn;q=0.7,it;q=0.6',
'cache-control: max-age=0',
'cookie: ' . implode('; ', $cookies),
'upgrade-insecure-requests: 1',
'user-agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
);
$site = $all_activity_urls[$u];
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, "https://www.groupon.de/");
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $site);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// Parsing Cookie from the response header
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "curlResponseHeaderCallback");
$data = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status_code === 200)
{
// Ready data for parsing
$document = new DOMDocument();
$document->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">' . $data);
$xpath = new DOMXpath($document);
$title = '';
$availability = '';
$price = '';
$base_price = '';
$link = '';
$image = '';
$link = $all_activity_urls[$u];
// Scraping Availability
$raw_availability = $xpath->query('//div[#data-bhw="DealHighlights"]/div[0]/div/div');
$availability = $raw_availability->item(0)->nodeValue;
// Scraping Title
$raw_title = $xpath->query('//h1[#id="deal-title"]');
$title = $raw_title->item(0)->nodeValue;
// Scraping Price
$raw_price = $xpath->query('//div[#class="price-discount-wrapper"]');
$price = trim(str_replace(array("$", "€", "US", " "), array("", "", "", ""), $raw_price->item(0)->nodeValue));
// Scraping Old Price
$raw_base_price = $xpath->query('//div[contains(#class, "value-source-wrapper")]');
$base_price = trim(str_replace(array("$", "€", "US", " "), array("", "", "", ""), $raw_base_price->item(0)->nodeValue));
// Creating Final Data Array
array_push($final_data, array(
'link' => $link,
'availability' => $availability,
'name' => $title,
'price' => $price,
'baseprice' => $base_price,
'img' => $image,
));
}
else
{
$link = $all_activity_urls[$u];
if ($status_code === 429)
{
$status_msg = ' - Too Many Requests';
}
else
{
$status_msg = '';
}
array_push($final_data, array(
'link' => $link,
'status' => $status_code . $status_msg,
));
}
echo 'before break - ' . date('h:i:s') . "<br>";
sleep(5);
echo 'after break - ' . date('h:i:s') . "<br>";
flush();
}
echo 'script end - ' . date('h:i:s') . "<br>";
// Converting data to XML
$activities = new SimpleXMLElement("<?xml version=\"1.0\"?><activities></activities>");
array_to_xml($final_data, $activities);
$xml_file = $activities->asXML('activities.xml');
if ($xml_file)
{
echo 'XML file have been generated successfully.';
}
else
{
echo 'XML file generation error.';
}
}
else
{
$activities = new SimpleXMLElement("<?xml version=\"1.0\"?><activities></activities>");
$activities->addChild("error", htmlspecialchars("No URL scraped from sitemap. Stoping script."));
$xml_file = $activities->asXML('activities.xml');
if ($xml_file)
{
echo 'XML file have been generated successfully.';
}
else
{
echo 'XML file generation error.';
}
}
// Recursive Function for creating XML Nodes
function array_to_xml($array, &$activities)
{
foreach ($array as $key => $value)
{
if (is_array($value))
{
if (!is_numeric($key))
{
$subnode = $activities->addChild("$key");
array_to_xml($value, $subnode);
}
else
{
$subnode = $activities->addChild("activity");
array_to_xml($value, $subnode);
}
}
else
{
$activities->addChild("$key", htmlspecialchars("$value"));
}
}
}
// Cookie Parsing Function
function curlResponseHeaderCallback($ch, $headerLine)
{
global $cookies;
if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1)
{
$cookies[] = $cookie[1];
}
return strlen($headerLine); // Needed by curl
}
There is a mess of cookies in your snippet. The callback function just appends cookies to the array regardingless of whether they already exist or not. Here is a new version which at least seems to work in this case since there are no semicolon-seperated multiple cookie definitions. Usually the cookie string should be even parsed. If you have installed the http extension you can use http_parse_cookie.
// Cookie Parsing Function
function curlResponseHeaderCallback($ch, $headerLine)
{
global $cookies;
if (preg_match('/^Set-Cookie:\s*([^;]+)/mi', $headerLine, $match) == 1)
{
if(false !== ($p = strpos($match[1], '=')))
{
$replaced = false;
$cname = substr($match[1], 0, $p+1);
foreach ($cookies as &$cookie)
if(0 === strpos($cookie, $cname))
{
$cookie = $match[1];
$replaced = true;
break;
}
if(!$replaced)
$cookies[] = $match[1];
}
var_dump($cookies);
}
return strlen($headerLine); // Needed by curl
}
I want to download the google search big image. Below is my code, which is working fine for download small image from google search.
<?php
include_once('simple_html_dom.php');
set_time_limit(0);
$fp = fopen('csv/search.csv','r') or die("can't open file");
$csv_data = array();
while($csv_line = fgetcsv($fp)) {
for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
$imgname = $csv_line[$i];
$search_query = $csv_line[$i];
$search_query = urlencode(trim($search_query));
$html=file_get_html('http://images.google.com/images?as_q='. $search_query .'&hl=en&imgtbs=z&btnG=Search+Images&as_epq=&as_oq=&as_eq=&imgtype=&imgsz=m&imgw=&imgh=&imgar=&as_filetype=&imgc=&as_sitesearch=&as_rights=&safe=images&as_st=y');
$image_container = $html->find('div#rcnt', 0);
$images = $html->find('img');
$image_count = 1; //Enter the amount of images to be shown
$i = 0;
foreach($images as $image){
$srcimg = $image->src;
if($i == $image_count) break;
$i++;
$randname = $imgname.".jpg";
$randname = "Images/".$randname;
file_put_contents("$randname", file_get_contents($srcimg));
}
}
}
?>
Any idea?
This worked for me. simple_html_dom.php wouldn't do the trick since the 'big image' is inside a snippet of JSON near each thumbnail in the DOM.
<?php
$search_query = "Some Keyword"; //change this
$search_query = urlencode( $search_query );
$googleRealURL = "https://www.google.com/search?hl=en&biw=1360&bih=652&tbs=isz%3Alt%2Cislt%3Asvga%2Citp%3Aphoto&tbm=isch&sa=1&q=".$search_query."&oq=".$search_query."&gs_l=psy-ab.12...0.0.0.10572.0.0.0.0.0.0.0.0..0.0....0...1..64.psy-ab..0.0.0.wFdNGGlUIRk";
// Call Google with CURL + User-Agent
$ch = curl_init($googleRealURL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux i686; rv:20.0) Gecko/20121230 Firefox/20.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$google = curl_exec($ch);
$array_imghtml = explode("\"ou\":\"", $google); //the big url is inside JSON snippet "ou":"big url"
foreach($array_imghtml as $key => $value){
if ($key > 0) {
$array_imghtml_2 = explode("\",\"", $value);
$array_imgurl[] = $array_imghtml_2[0];
}
}
var_dump($array_imgurl); //array contains the urls for the big images
die();
?>
I think rather than crawling the page you can you the google custom search api
for more details here the url:
https://developers.google.com/custom-search/json-api/v1/overview
i want to parse a website but
i always get an Error: service out of order.
No matter what start or end string i give.
I also tried to use an other URL and i copied
full examples from other users that works for them
but not for me. I also tried to increase the Size to 20000.
But nothing is working.
Here is my php-Script:
<?php
// URL, die durchsucht werden soll
$url = "http://cordis.europa.eu/project/rcn/85400_en.html";
// Zeichenfolge vor relevanten Einträgen
$startstring = "<div class='tech'><p>";
// bis zum nächsten html tag bzw. Zeichenfolge nach relevanten Einträgen
$endstring = "<";
$file = #fopen ($url,"r");
if($file)
{
echo "URL found<br>";
}
if (trim($file) == "") {
echo "Service out of order - File:".$file."<br>";
} else {
$i=0;
while (!feof($file)) {
// Wenn das File entsprechend groß ist, kann es unter Umständen
// notwendig sein, die Zahl 2000 entsprechend zu erhöhen. Im Falle
// eines Buffer-Overflows gibt PHP eine entsprechende Fehlermeldung aus.
$zeile[$i] = fgets($file,20000);
$i++;
}
fclose($file);
}
// Data filtering
for ($j=0;$j<$i;$j++) {
if ($resa = strstr($zeile[$j],$startstring)) {
$resb = str_replace($startstring, "", $resa);
$endstueck = strstr($resb, $endstring);
$resultat .= str_replace($endstueck,"",$resb);
$resultat .= "; ";
}
}
// Data output
echo ("Result = ".$resultat."<br>");
return $resultat;
Any help is appreciate.
thanks in advance
EDIT: The URL is found and file has a value: Resource id #3
Try
<?php
// URL, die durchsucht werden soll
$url = "http://cordis.europa.eu/project/rcn/85400_en.html";
$html = file_get_contents($url);
if ($html === false) {
//Service unavailable
echo 'Service unavailable';
return;
}
$dom = new DOMDocument;
$dom->loadHTML($html);
$xpath = new DomXpath($dom);
$div = $xpath->query("//*[#class='tech']")->item(0);
$output = trim($div->textContent);
// Data output
echo ("Result = " . $output. "<br>");
return $output;
Use this it will give expected output.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://cordis.europa.eu/project/rcn/85400_en.html");
curl_setopt($ch, CURLOPT_GET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, '');
$headers = array();
$headers[] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
$headers[] = 'Accept-Encoding:gzip, deflate, sdch';
$headers[] = 'Accept-Language:en-US,en;q=0.8';
$headers[] = 'Cache-Control:max-age=0';
$headers[] = 'Connection:keep-alive';
$headers[] = 'Cookie:CORDIS=14.141.177.158.1441621012200552; PHPSESSID=jrf2e3t4vu56acdkf9np0tat06; WT_FPC=id=14.141.177.158-1441621016.978424:lv=1441605951963:ss=1441604805004
Host:cordis.europa.eu';
$headers[] = 'User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36';
$headers[] = 'Host:cordis.europa.eu';
$headers[] = 'Request URL:http://cordis.europa.eu/project/rcn/85400_en.html';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument;
$dom->loadHTML($server_output);
$xpath = new DomXpath($dom);
$div = $xpath->query("//*[#class='tech']")->item(0);
$data = trim($div->textContent);
echo $data;
?>
Output
I am trying to get the attachment url in $getAttachmentURL so it is possible to download the file. I get the error code 1006 - not found.
<?php
$baseURL = "https://api.smartsheet.com/1.1";
$sheetsURL = $baseURL."/sheets/";
$getSheetURL = $baseURL."/sheet/3712544801089412";
$rowsURL = $baseURL."/sheet/3712544801089412/rows";
$rowAttachmentsURL = $baseURL."/sheet/3712544801089412/row/{{ROWID}}/attachments";
$getAttachmentURL = $baseURL."/sheet/3712544801089412/attachment/{{ATTACHMENTID}}";
// Insert your Smartsheet API Token here
$accessToken = "xxx";
// Create Headers Array for Curl
$header = array(
"Authorization: Bearer ".$accessToken,
"Content-Type: application/json"
);
// Connect to Smartsheet API to get Selected Sheet
$curlSession = curl_init($getSheetURL);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$getSheetResponseData = curl_exec($curlSession);
$sheetObj = json_decode($getSheetResponseData);
echo "<h1>Sheet name: ".$sheetObj->name."</h1>";
echo "<br>";
//table start
echo "<table>";
echo "<td>"."Attachment"."</td>";
foreach($sheetObj->columns as $column) {
echo "<td>".$column->title."</td>";
}
echo "<tr>";
foreach($sheetObj->rows as $row) {
$rowAttachmentsURL = str_replace('3712544801089412', $row->id, $rowAttachmentsURL);
$chosenRow = $row->id;
$rowAttachmentsURL = $baseURL."/sheet/3712544801089412/row/$chosenRow/attachments";
$rowAttachmentsURL = str_replace($chosenRow, $row->id, $rowAttachmentsURL);
$curlSession = curl_init($rowAttachmentsURL);
$rowsResponse = curl_exec($curlSession);
// Assign response to variable
$addRowsObj = json_decode($rowsResponse);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$getAttachmentsResponse = curl_exec($curlSession);
// Assign response to variable
$attachment = json_decode($getAttachmentsResponse);
$rowAttachTags = array($chosenRow->id, $theSheet->id, $attachments[0]->id);
$rowAttachVals = array($addRowsObj->result[0]->id, $theSheet->id, $attachments[0]->id);
$getAttachmentURL = str_replace($rowAttachTags, $rowAttachVals, $getAttachmentURL);
$type = $attachment[0]->mimeType;
$size = $attachment[0]->sizeInKb;
$filename = $attachment[0]->name;
// Print headers
header("Content-Type: $type");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename=$filename");
echo "<td><a href='".$getAttachmentURL."'>".$attachment[0]->name."</a></td>";
//echo "<td>".$attachment[0]->id."</td>";
foreach($row->cells as $cell) {
echo "<td>".$cell->value."</td>";
}
echo "<td></td><td></td><td></td>";
echo "</tr>";
}
echo "</table>";
I am a little confused abort it all so i really need your help
The row attachments url should be rows not row
Yours:
$rowAttachmentsURL = $baseURL."/sheet/3712544801089412/row/{{ROWID}}/attachments";
Correct:
$rowAttachmentsURL = $baseURL."/sheet/3712544801089412/rows/{{ROWID}}/attachments";
I tried to validating my XML, but I did not get a proper response, anyone tell me how to validate my post operation? And what is the way of bulk posting with free of category and location?
I have free account in Craigslist. I use this code:
<?php error_reporting(E_ALL);
ini_set('display_errors', '1');
$name='my username';//$_POST['name']; // Get from form or get from DB one per xml
$password= 'my password';//$_POST['password'];
$id='my account ID';//$_POST['id'];
$xmlStart='<?xml version="1.0"?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">';
$channelStart='<channel>';
$channelItems='<items>';
$channelItemsEnd='</items>';
$channelAuth='<cl:auth username="'.$name.'"
password="'.$password.'"
accountID="'.$id.'"/>';
$channelEnd='</channel>';
$xmlEnd='</rdf:RDF>';
$channelItems .='<rdf:li rdf:resource="$179000 / 3br - 3 Bed/1 Bath Great NE Heights Locating!! No Bank Qualifying!! Owner Fi (NE Albuquerque)"/>';
$items='';
//set the content type to xml
//header("Content-Type: text/xml");
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody = '<rdf:RDF xmlns="http://purl.org/rss/1.0/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">';
$xmlBody .= "<XML>";
// Run a select query to get my letest 6 items
// Connect to the MySQL database
mysql_connect("localhost","root","");
mysql_select_db('new_listing');
//$dynamicList = "";
$sql = mysql_query("SELECT * FROM listing ORDER BY id");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
// Create channel item string
$channelItems .='';
$id = $row['id'];
$name = $row['username'];
$password= $row['password'];
$address = $row['address'];
$Posting_type = $row['posting_type'];
$category = $row['category'];
$location = $row['location'];
$posting_title = $row['posting_title'];
$specific_loc = $row['specific_loc'];
$postal = $row['postal_code'];
$description = $row['description'];
$reply_to = $row['reply_to'];
$rent = $row['rent'];
$sqft = $row['sqft'];
$bedrooms = $row['bedrooms'];
$bathrooms = $row['bathrooms'];
$housing = $row['housing_type'];
$laundry = $row['laundry'];
$parking = $row['parking'];
$wheelchair = $row['wheelchair'];
$smoking = $row['smoking'];
$furnished = $row['furnished'];
$street = $row['street'];
$cross_street = $row['cross_street'];
$city = $row['city'];
$zip_code = $row['zip_code'];
$date_d = $row['date_d'];
$time_t = $row['time_t'];
$image = $row['images'];
$items .= '
<item rdf:about="real estate">
<cl:category>"housing"</cl:category>
<cl:area>"NE Albuquerque"</cl:area>
<cl:housingInfo price="$179000"
bedrooms="3"
sqft="1400"/>
<cl:replyEmail privacy="C">email address</cl:replyEmail>
<cl:brokerInfo companyName="Your Company name"
feeDisclosure="fee disclosure here" />
<title>"$179000 / 3br - 3 Bed/1 Bath Great NE Heights Locating!! No Bank Qualifying!! Owner Fi (NE Albuquerque)"</title>
<description><![CDATA["3 Bedroom, 1 Bath 1400sqft home with 1 car garage,
Lease With Option To Buy, No Bank Qualifying!!
Price $179,000, $1200 lease per month + $15,000 down
Great Location in NE Heights close to schools, shopping and jobs!!
Very Desirable Location! Call 505-264-7942 and ask for Robert"]]></description>
</item>';
// End while loop
}
mysql_close();
// close the mysql database connection
//$xmlBody .= "</XML>";
$xmlToSubmit=$xmlStart.$channelStart.$channelItems.$channelAuth.$channelItemsEnd.$channelEnd.$items.$xmlEnd;
class cURL {
var $headers;
var $user_agent;
function cURL()
{
$this->headers[] = 'Connection: Keep-Alive';
$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$this->user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
}
function post($url,$data) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($process, CURLOPT_POST, 1);
$return = curl_exec($process);
$info = curl_getinfo($process);
curl_close($process);
return $info;
}
}
$cc = new cURL();
$url = 'https://post.craigslist.org/bulk-rss/post';
$output = $cc->post($url,$xmlToSubmit);
//echo $output;
print_r($output);
} ?>