I’m working on a website which should be fully visible for users in a place that Facebook.com is banned for them. so my Facebook like box plugin will not appear for them. ( in order to not localize this question, assume that I want to bypass all client-side firewalls and show like box plugin as a simple HTML in my website (my website is not banned there)).
My server can access Facebook.com and I thought that i can get content of my plugin using curl (in my server’s computer) and then execute and show content of that page as a simple HTML in any part of my website. So I just wrote following script:
<?
$c = curl_init('https://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fstevejobs&width=292&height=258&colorscheme=dark&show_faces=true&border_color&stream=false&header=false');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.facebook.com', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
', 'Accept-Language: en-us,en;q=0.5', 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Accept-Encoding: gzip, deflate'));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt(CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$html = curl_exec($c);
if (curl_error($c))
die(curl_error($c));
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
?>
Surprisingly above code works for https://www.youtube.com( which is banned there too ) or https://www.google.com but not working with that URL or even simply https://www.facebook.com in my server.
Another question : if I use https://www.youtube.com instead of Facebook.com I still can’t get CSS files or Javascript files which used in YouTube.com( because they are banned too and clients can’t download it either). I just can see texts and some images. I also want curl to automatically get content of CSS and Javascript files.
I also used YQL in order to get content of like box plugin from Facebook.com but I got following result:
YQL statement:
select * from html where url = 'https://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fstevejobs&width=292&height=258&colorscheme=dark&show_faces=true&border_color&stream=false&header=false'
Result:
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
yahoo:count="0" yahoo:created="2011-11-11T11:41:10Z" yahoo:lang="en-US">
<diagnostics>
<publiclyCallable>true</publiclyCallable>
<url
error="Redirected to a robots.txt restricted URL: https://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fstevejobs&amp;width=292&amp;height=258&amp;colorscheme=dark&amp;show_faces=true&amp;border_color&amp;stream=false&amp;header=false"
execution-start-time="1" execution-stop-time="6"
execution-time="5" http-status-code="403"
http-status-message="Forbidden" proxy="DEFAULT"><![CDATA[https://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fstevejobs&width=292&height=258&colorscheme=dark&show_faces=true&border_color&stream=false&header=false]]></url>
<user-time>6</user-time>
<service-time>5</service-time>
<build-version>23377</build-version>
</diagnostics>
<results/>
</query>
It looks like there are some problem with facebook.com’s robots.txt. I should mention that above YQL statement works for other websites( like https://www.youtube.com or https://www.yahoo.com ).
Thanks in advance
there are mistakes in your code:
1- change $c to $ch in all parts of your code.
2- add “echo $html” after curl_exec function.
3- as @Dan mentioned in a comment, CURLOPT_HTTPHEADER isn’t necessary. simply remove it.
4- setting curlopt_cookiejar isn’t necessary but I always set it with curl. ( just to make sure that everything works fine )
5- remove everything before
<!DOCTYPEin order to show content properly.try following code: