Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Can someone verify this is the proper way to fake a referer? For one reason or another, the site I'm loading isn't verifying it as a page load/view and I can only assume it's because the referer is wrong.

#!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent("googlebot.com "); # Create a request my $req = HTTP::Request->new(GET => 'http://dragcave.ath.cx/viewdragon +/Vjwf'); $req->header('Referer', 'http://www.google.com'); $reg->agent('testing'); print header, start_html(); print "done";

Replies are listed 'Best First'.
Re: Faking referer with LWP::UserAgent
by erroneousBollock (Curate) on Oct 06, 2007 at 03:39 UTC
    Typos aside ($reg), that does look like it sets the referring URL correctly.

    Perhaps the site requires that you obtain a cookie by visiting the referring URL's page ?

    Also, I don't see where you're actually getting the page. (ie: calling $ua->get)

    -David

      I'm confused and have this now. Am I closer to getting it right? Not it says it cannot find header via package UserAgent
      #!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use LWP::UserAgent; use CGI::Carp qw/fatalsToBrowser/; print header, start_html(); my $ua = LWP::UserAgent->new; $ua->agent("google.com"); $ua->header('Referer', 'http://www.google.com'); $ua->agent('testing'); $ua->get('http://dragcave.ath.cx/viewdragon/Vjwf'); print $ua->content;
        Something like this should work:

        use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent("google.com"); my $response = $ua->get('http://dragcave.ath.cx/viewdragon/Vjwf', Refe +rer => 'http://www.google.com'); print $response->content;
        However, I really doubt thats the kind of security they'd be using. Usually, the referring URL would be a URL on their own site. If they discriminate at all, it'll be purely on user-agent string.

        -David

        my $ua = LWP::UserAgent->new(); $ua->agent("google.com"); my $req = HTTP::Request->new(GET => $uri); $req->header('Referer', 'http://www.google.com'); $ua->request($req);