It am using curl in php to get contents from external website. I am getting contents from websites like https://www.flickr.com/. The site will show different content (in different languages) for browsers in different languages. I want to get English content only. I have tried:
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12");
But it doesn't work. It retrieve Chinese contents instead. Any advice?
From Chrome and Edge On the line of the specific resource you are interested in, you right-click with the mouse and you select "Copy as cURL" and it will generate a command line for you in your clipboard. Paste that in a shell to get a curl command line that makes the transfer.
You can use the -A or --user-agent command-line option to pass your own User-Agent string to Curl. By default, Curl sends its own User-Agent string to the server in the following format: "curl/version. number".
The syntax for the curl command is as follows: curl [options] [URL...] In its simplest form, when invoked without any option, curl displays the specified resource to the standard output. The command will print the source code of the example.com homepage in your terminal window.
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.
Set the Accept-Language
request header using CURLOPT_HTTPHEADER
like so:
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept-Language: en']);
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