• Hello,

    Can anyone explain why this is not working?

    wp_remote_get($imageUrl, array(‘timeout’ => 15, ‘headers’ => array(‘referer’ => ‘https://mydomain.net’))));

    the referer does not change, am i doing it wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Here is working example

    $response = wp_remote_get( 'https://www.ads-software.com' );
    if( is_array($response) ) {
        var_dump($response);exit;
    }

    check documentation here
    https://codex.www.ads-software.com/Function_Reference/wp_remote_get

    Thread Starter Rado

    (@jeriksson)

    can you give a working example using the second example instead as in:

    wp_remote_get( 'https://www.example.com/index.php?action=foo', array( 'timeout' => 120, 'httpversion' => '1.1' ) );

    but with headers included instead?

    My logic makes me think that this would work:

    wp_remote_get( 'https://www.example.com/index.php?action=foo', array( 'timeout' => 120, 'headers' => 'https://mydomain.com' ) );

    but it doesn’t.

    What am i doing wrong?

    • This reply was modified 7 years, 10 months ago by Rado.
    • This reply was modified 7 years, 10 months ago by Rado.
    Moderator bcworkz

    (@bcworkz)

    I believe the value of the headers argument needs to be a complete header string as one might supply for a call to headers(), like so:
    'headers' => 'Referer: https://mydomain.com',

    If you have several headers to send, assign an array of string values, each element formatted as in my example. Also note that the Referer: header, as is tradition, is intentionally misspelled. “Referrer” is proper English.

    Untested though. If you still have trouble let me know and I’ll dig deeper.

    Thread Starter Rado

    (@jeriksson)

    thanks, but i can’t get it to work.

    wp_remote_get($imageUrl, array('headers' => 'Referer: https://mydomain.com')));

    $imageurl is the url to the image.

    i’m not quiet sure if it’s the header not being sent of some other issue, the origin of the issue started when a client requested that images that were hosted on his gallery would not to be visited directly, so i added some stuff to an htaccess file where the images reside:

    RewriteCond %{HTTP_REFERER} !^https://(www\.)?mydomain\.com.*$ [NC]  
    RewriteRule \.(jpg|jpeg|png|gif)$ / [L]

    which works perfectly as it should, when someone tries to visit https://mydomain.com/gallery/1.jpg they get a 404 , but if you visit https://mydomain.com and https://mydomain.com/gallery/1.jpg is linked on the page it will find the image as the referer header sent contains the mydomain.com.

    The issue is the client is also using a plugin which uses the function wp_remote_get when you publish a new post and it grabs the first image it finds in the post body automatically and attaches it as a thumbnail to the post. This is what am in trying to get to work here, but even if i add the referer header it will not work, it works instantly if i remove the htaccess code.

    Any ideas?

    • This reply was modified 7 years, 10 months ago by Rado.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_remote_get , headers referer?’ is closed to new replies.