I am calling three methods which executes xml using curl
$clientID=$newInvoice->reateClient($name,$organization,$email,$address,$country);
$invoiceID=$newInvoice->CreateInvoice($clientID,$invoiceNumber,$itemName,$cost,$quantity);
echo $newInvoice->SendInvoice($invoiceID);
when I use these all three method then first executes properly but second and third shows error that : String could not be parsed as XML
Its is working fine if I call each method one at a time by commenting other two method. Can anyone please help
php code sample($xml_request contains xml and it seems ok because I can execute without any error if I execute one method at a time by commenting any other two ):
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_USERPWD, $token.':123');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml_request='.$xml_request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Invoicera API Test 1.0");
$curl_result = curl_exec($ch);
curl_close ($ch);
return $curl_result;
Related
I use curl in php to get data from a website and add to my mysql database.
But the string I get is formatted strange. i've tried some method but didn't help me. who used to deal with it please give me your solution.
My curl method here:
function grab_page($site){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $site);
ob_start();
return curl_exec($ch);
ob_end_clean();
curl_close ($ch);
}
After get it, i echo the html, my method here:
function getDetailPage(){
$detailData = grab_page("https://www.deliverynow.vn/ho-chi-minh/hanuri-quan-an-han-quoc-xo-viet-nghe-tinh");
echo htmlspecialchars($detailData);
}
The html string i got is change to weird character like: Món khác . But it should be like this: Món khác
Use html_entity_decode to restore characters.
I'm learning regex, php & cUrl and would like to get Google Image html
(for example : https://www.google.fr/search?q=terrorist&biw=1920&bih=1008&source=lnms&tbm=isch&gws_rd=ssl#tbm=isch&q=love)
I tried a lot of different answers but I don't understand why, surprisingly, when I do
<?php
function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($conn2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($conn2, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$get_page = curl_get_contents("https://www.google.fr/search?q=terrorist&biw=1920&bih=1008&source=lnms&tbm=isch&gws_rd=ssl#tbm=isch&q=love");
echo $get_page;
?>
I've got a very different result than in browser. All images links are dead for example.
Does anyone know why ? And what could I do to fix it?
Thanx a lot !!
There are 2 search queries in this request as shown below
https://www.google.fr/search?q=terrorist&biw=1920&bih=1008&source=lnms&tbm=isch&gws_rd=ssl#tbm=isch&q=love
try
https://www.google.fr/search?q=love&biw=1920&bih=1008&source=lnms&tbm=isch&gws_rd=ssl#tbm=isch
It looks like its returning the first query in the browser and then running the second, but it wont do the second request via curl.
This works for me:
<?php
function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($ch);
var_dump(curl_error($ch));
curl_close($ch);
return $data;
}
$get_page = curl_get_contents("https://www.google.fr/search?q=love&biw=1920&bih=1008&source=lnms&tbm=isch&gws_rd=ssl#tbm=isch");
echo $get_page;
?>
EDIT: After further research this is an unsupported way of doing this, You should be using Google Custom Search API. The way that you are doing it will result in Google detecting misuse and presenting you with Captcha requests or maybe even blocking you.
I have a script wherein I would like to send off two HTTPS calls to a master database via cURL with similar variables. I have tested each script individually to be working fine, but when I combine the two the second one is blocked. Here is what it looks like when they are combined:
$idno=’123’;
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, 'https://mysite.com/integration.php?type=CANCEL&idnumber='.$idno.'');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$Response = curl_exec($curl);
return $Response;
curl_close($curl);
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_VERBOSE, 1);
curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl2, CURLOPT_TIMEOUT, 30);
curl_setopt($curl2, CURLOPT_URL, 'https://mysite.com/integration2.php?customer_id=CUSOTMER&idnumber='.$idno.’&type=CANCEL');
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
$Response2 = curl_exec($curl2);
return $Response2;
curl_close($curl2);
I have tried a handful of variations to open and close the cURL calls, but no luck. Anything standing out here as off?
First of all, you have syntax error on your code. Please fix those. For example $idno=’123’; should be $idno='123';
Now, come to the point about why second curl is not functioning!!! What is the return doing after your first curl request??
$Response = curl_exec($curl);
return $Response; <--- its returning you back from here
That's why the second curl is always unreachable!! Remove that unwanted return block.
I have found a new way to rewrite the code for multi-curl requests. This is well defined in the cURL documentation here:
http://us2.php.net/manual/en/function.curl-multi-exec.php
Simple script but does not seem to be posting the fields across correctly on the second server. The only difference in php info is NSS/3.12.7.0 and NSS/3.12.9.0. One is on https and the other is not, is there another option that I am missing here?
$ch=curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$result=curl_exec($ch);
curl_close($ch);
Add this it will turn off SSL verification :
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
I found this code
(full version here http://blog.loicg.net/developpement-web/lire-twitter-stream-php-curl)
function read_the_stream($sTrackingList){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://stream.twitter.com/1/statuses/filter.json');
curl_setopt($ch,CURLOPT_USERPWD,TWITTER_LOGIN.':'.TWITTER_PASSWORD);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, '');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Twitter-Client: ItsMe','X-Twitter-Client-Version: 0.1','X-Twitter-Client-URL: http://rien.net/'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,"track=".$sTrackingList);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'write_callback');
curl_exec($ch);
curl_close($ch);
}
It's work for me but now i don't know how to stop it (for making test it's horrible, my new php file not interpreted!)
You should either put this code inside a script that is not executed on a webpage (like a daemon) or you should not use the stream.
If you want to get only 100 tweets, then use some of the other twitter API for that.
If you want a stop button, consider:
have your other script populate some database (or a queue like redis or ActiveMQ) and then you can have your webpage get your own stream using AJAX
Simply using AJAX to call a script that reads the feeds.