Utf-8 url get with curl - unicode

i am trying to visit some urls with non latin characters using curl, the problem is when i visit i get no response. My browser has no problem visiting them, i checked out the string transformations and it seems i am visiting
"http://www.linkedin.com/pub/j-rgen-a-tr-ff/7/606/68a"
while my browser visits
"http://se.linkedin.com/pub/j%C3%B6rgen-a-tr%C3%A4ff/7/606/68a"
How do i convert that string so the curl succeeds?
function hitFormGet($loginURL, $loginFields, $referer,$cookieString)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
//curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
//curl_setopt( $ch, CURLOPT_COOKIE,$cookieString);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_VERBOSE, 1 );
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate,sdch');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Googlebot/2.1 (+http://www.googlebot.com/bot.html)");
curl_setopt($ch, CURLOPT_URL, $loginURL.$loginFields);
curl_setopt($ch, CURLOPT_REFERER, $referer);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $loginFields);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
$res=hitFormGet("http://se.linkedin.com/pub/j%C3%B6rgen-a-tr%C3%A4ff/7/606/68a","","","");

It looks like you are visiting linkedin from Sweden. That's why you are redirected to se.linkedin.com. To convert URL as expected you can apply urlencode() on your dynamic url part as in your example on: j-rgen-a-tr-ff/7/606/68a.
It should work.

Related

How I can update old realex payments code to latest 3ds v2?

my old code is using xml and json is like this need to update this to latest 3D Secure v2.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://epage.payandshop.com/epage-remote.cgi");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "payandshop.com php version 0.9");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // this line makes it work under https
$response = curl_exec ($ch);
curl_close ($ch);

saving form data using curl to controller in codeigniter

There is a form and i am getting $_POST data.
The code is this
if (isset($_POST) && $_POST) {
$fields = $_POST;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://example.org/index.php/public/example/SaveExample");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
$output = curl_exec($ch);
}
But the call to controller is not working.what will be the issue.anybody pls help

How to fetch images using confluence API?

I have created a script that fetches all the articles from https://insuredhq.atlassian.net/ below is the code I have used.
$username = '##########';
$password = '##########';
$url = "https://insuredhq.atlassian.net/wiki/rest/api/content?spaceKey=IUM&id=Completing%20a%20Task&expand=space,body.view,version,container";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
curl_close($ch);//print_r($result);
$result = json_decode($result);
echo "<pre>";
print_r($result);
I have checked those image src property and they are dynamic urls like /wiki/download/attachments/13303822/Dashboard.png?version=1&modificationDate=1462935137147&api=v2 and even I change them to static urls like https://insuredhq.atlassian.net/wiki/download/attachments/13303822/Dashboard.png?version=1&modificationDate=1462935137147&api=v2 but still they are not being displayed.
For detailed example please check this link http://hunaniinfotech.com/insecuredhq/article.php?id=13303841

Simple CURL redirect

I have been around this site looking for solution to my question, some answers look close but not as much to find the solution to my issue
I have PHP curl to login to certain site and redirect to certain link while logged in.
***First to log:***
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https >somesite');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
curl_setopt($ch, CURLOPT_REFERER, 'some other site');
curl_setopt($ch, CURLOPT_TIMEOUT, 220);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).DS.'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).DS.'cookies.txt');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,'userid='.$log.'&password='.$pass.);
$content = curl_exec( $ch )
***then run this to get away from page with ads ***
$info = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$fnd='ads'; ***// check to see if has ads***
$pos=strpos($info, $fnd);
if ($pos!==false)
{
$url1 = "https - link to redirect while logged id"; // ***I have this link for sure***
$ch1 = curl_init();
curl_setopt ($ch1, CURLOPT_URL, $url1);
curl_setopt ($ch1, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch1, CURLOPT_USERAGENT, $uagent);
curl_setopt( $ch1, CURLOPT_HEADER, 1);
curl_setopt ($ch1, CURLOPT_COOKIESESSION, 0);
curl_setopt ($ch1, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch1, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch1, CURLOPT_CONNECTTIMEOUT ,100);
curl_setopt ($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch1, CURLOPT_COOKIEJAR, dirname(__FILE__).DS.'cookies.txt');
curl_setopt ($ch1, CURLOPT_COOKIEFILE, dirname(__FILE__).DS.'cookies.txt');
curl_setopt ($ch1, CURLOPT_POST, 0);
$content = curl_exec ($ch1);
but that is not working.
Who would kindly answer me?
Thank you.
I heard a dialog in a horror movie(not sure though) long time back "Easy Pizzy, that means crazy". Solution of your problem is easy, but not until you know it :-)
Close your curl to make sure it saves the cookies into the file. Otherwise its always empty and hence not working on second call.
// use it before second curl call
curl_close($ch);
In fact its always a good practice to close the curl instance after the needs are done!

How to publish a photo to a Facebook page as a separate story

If I use the Facebook API to publish a photo to a page they appear as single story.
$args = array(
'message' => '',
);
$args["picture"] = '#' . realpath($file);
$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token='.$token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
If I publish from Facebook they appear correctly as a single story for each picture.
How to do this programmatically?