0

cUrl set language header

I was trying to get the source code of Facebook's homepage by using cURL, but it was all Chinese due to the location of my server host. For this reason, I added Accept-Language of CURLOPT_HTTPHEADER to change the language to English, but failed. According to the answer I quoted above, below is the PHP code of cURL I tried:

<?php

$url = "http://www.facebook.com/";

if(isset($_SERVER['HTTP_USER_AGENT']))
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
else
    $user_agent = "";

$options = array(
    CURLOPT_RETURNTRANSFER => true,     // return web page
    CURLOPT_HEADER         => false,    // don't return headers
    CURLOPT_FOLLOWLOCATION => true,     // follow redirects
    CURLOPT_HTTPHEADER     => array("Accept-Language: en-US;q=0.6,en;q=0.4"),
    CURLOPT_USERAGENT      => $user_agent);

$ch      = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err     = curl_errno($ch);
$errmsg  = curl_error($ch);
$header  = curl_getinfo($ch);
curl_close($ch);

echo $content;

?>

But it still showed Chinese:

The Facebook was all Chinese.

How can I solve this problem?

Community
  • 1
  • 1
Banana Code
  • 759
  • 1
  • 12
  • 28
  • the accept header is just a SUGGESTION to the server as to what language it should send back, but like all suggestions, it can be ignored. If FB decides that you're chinese, you're going to get chinese. – Marc B Aug 23 '16 at 18:58
  • @MarcB So do you have any solution to solve this problem? I'm not used to Chinese. – Banana Code Aug 24 '16 at 02:02
  • The right way to use this option: https://stackoverflow.com/questions/24115035/how-to-set-browser-language-when-using-curl-to-retrieve-contents – Tom Jun 06 '19 at 06:26

0 Answers0