# WordPress: 本地化gravatar头像请求以解决无法显示的问题

## 示例PHP代码

gravatar头像就是一张图片而已，使用下面的php代码+cURL转发一次即可：

<?php
$path = urldecode($_SERVER['QUERY_STRING']);
$url = 'http://www.gravatar.com/avatar/'.$path;
$headers = []; if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
$headers[] = 'If-Modified-Since: '.$_SERVER['HTTP_IF_MODIFIED_SINCE'];
if(isset($_SERVER['HTTP_IF_NONE_MATCH']))$headers[] = 'If-None-Match: '.$_SERVER['HTTP_IF_NONE_MATCH'];$ch = curl_init($url); if(count($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$headers = []; } curl_setopt($ch, CURLOPT_HEADERFUNCTION,
function($handle,$line) use (&$headers) {$headers[] = substr($line, 0, -2); if(strlen($line) === 2) {
for($i=0,$c=count($headers)-1;$i<$c;$i++) {
header($headers[$i]);
}
}
return strlen($line); }); curl_exec($ch);
curl_close(\$ch);


## 代码使用方式

### 传递gravatar参数

gravatar原链接形式：https://secure.gravatar.com/avatar/4531b758b89c9df8e8e8a5894bed9115?s=64

encodeURIComponent("4531b758b89c9df8e8e8a5894bed9115?s=64") 得到 4531b758b89c9df8e8e8a5894bed9115%3Fs%4D64

## 测试
{"ft_lang_label":"__label__zh","ft_lang_prob":0.65164065,"math_prob":0.95966214,"size":1865,"snap":"2020-10-2020-16","text_gpt3_token_len":990,"char_repetition_ratio":0.12520151,"word_repetition_ratio":0.0,"special_character_ratio":0.30294907,"punctuation_ratio":0.20149253,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97270733,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-04-05T23:02:54Z\",\"WARC-Record-ID\":\"<urn:uuid:c6535518-bd6b-4c69-b29e-3b4b06fa3fdf>\",\"Content-Length\":\"10197\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:83d91125-08cc-4ac8-afa9-5b010e546406>\",\"WARC-Concurrent-To\":\"<urn:uuid:a0e8f954-7ee7-442f-9337-3bc3cd782be2>\",\"WARC-IP-Address\":\"144.34.245.161\",\"WARC-Target-URI\":\"https://twofei.com/521/\",\"WARC-Payload-Digest\":\"sha1:ODH6XFV7ILF5B4RAN6S4UT6BK3KAFFKX\",\"WARC-Block-Digest\":\"sha1:X6BZYO4IR3C2YALAODMXFFC3L4T5J6QA\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585371611051.77_warc_CC-MAIN-20200405213008-20200406003508-00345.warc.gz\"}"}