How can I set a language header for my cURL request? e.g. now I get the homepage of facebook.com in dutch, probably because my server is in the Netherlands / default language send by headers?..
I prefer english before dutch in this case so I tried to set an httpheader in curl but I make no sense? What do I do wrong or what should I have to set?
(zend notation)
CURLOPT_HTTPHEADER => 'Accept-Language: en-US;q=0.6,en;q=0.4',
Thanks in advance!
To send an HTTP header with a Curl request, you can use the -H command-line option and pass the header name and value in "Key: Value" format. If you do not provide a value for the header, this will remove the standard header that Curl would otherwise send. The number of HTTP headers is unlimited.
To pass multiple headers in a curl request you simply add additional -H or --header to your curl command. For standard HTTP header fields such as User-Agent, Cookie, Host, there is actually another way to setting them.
The user can change the Accept-Language header sent by the browser using the browser's preference settings. E.g., in Chrome, go to “Settings”, click on “Show advanced settings...”, scroll down to “Languages”, click on “Language and input settings...”, and then add languages and drag to order them.
The Accept-Language header is information about the user's language preferences that is passed via HTTP when a document is requested. Mainstream browsers allow these language preferences to be modified by the user.
I arrived at this page looking for a way to pass the language header to curl at the command line. If you want to set headers in a bash one-liner, use -H Accept-Language
$ curl -s -H 'Accept-Language: es' -XGET "http://www.google.com"
<!doctype html>
<html itemscope="" itemtype="http://schema.org/WebPage" lang="es-419">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta content="/logos/doodles/2016/united-states-elections-2016-4829342880235520-hp.gif" itemprop="image">
<meta content="Tu voz importa. �Encuentra tu casilla y vota! g.co/elections/dondevotar #Everyonein2016 #GoogleDoodle" property="og:description">
...
You have to add a header option in your request.
You will have something like this:
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
.....
$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);
All you have to do is add this line to your $options array:
CURLOPT_HTTPHEADER => array("Accept-Language: en-US;q=0.6,en;q=0.4"),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With