forcing a 'hit'

I need a perl script that will count a hit to another webpage that isn't on my server.  Basically, I'm looking for a cheater's way to generate hits.  I assure you that this is not a money making scam although it may sound like it.

When someone comes to my site, I want a perl script to be executed in a hidden frame.  This I can do.

I don't know how to do this, though:

If someone where to legitimately go to this other webpage through my site (click on their link), it would take them to the page: www.site2.com/index.cgi?id=number. Once on that page, the hit isn't counted unless the user follows a link on that page which goes to: www.site2.com/differentpage.html.  How can I use perl to go to differentpage.html and have site2.com think that the user clicked on the appropriate links?

I have the following script. However, it doesn't work.  For some reason site2.com knows better.  I think it's because the perl script is being executed from my server and site2.com is logging it as coming from my IP number instead of each user's IP number.  I know that anything is possible in Perl, so any ideas?  Thanks!

---Script that I have---

#!/usr/bin/perl
 
use HTTP::Request::Common qw(GET);
use LWP::UserAgent;
 
$ua = new LWP::UserAgent;
 
$ua->agent('Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt)');
 
$req = GET 'http://www.site2.com/differentpage.html';
$req->push_header(REFERER =>
'http://www.site2.com/index.cgi?id=number');

exit;


LVL 1
GorGor1Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
guadalupeConnect With a Mentor Commented:
#!/usr/local/bin/perl


#Parse form variables
if ($ENV{'REQUEST_METHOD'} eq "POST")
      {
          read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq "GET" )
      {
          $temp = $ENV{'QUERY_STRING'};
    }

@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}

if (($fields{url} ne "") && ($fields{url} =~ /http:\/\//))
{
print "Location: $fields{url}\n\n";
exit;
}



      


#Default if not found
open (LOG, ">>/virtual/ar/cgi-data/redirect.log");

print LOG "Error de syntax en $ENV{'HTTP_REFERER'}\n";

close LOG;

#default if all else fails
print "Location: http://www.xxx.com\n\n";

call like this

<a href="/cgi-bin/redirect.pl?
url=http://www.xxx.com">xxx</a>
0
 
GorGor1Author Commented:
Could you explain to me how to use this?  Where do I put in my particular variables?  Could you give me a little explanation on how it works?  I'm a perl dummy.  Thanks!

Tim
0
 
guadalupeCommented:
Ok the script goes in your cgi bin and make sure to give it the correct permissions:

chmod +x redirect.pl

then if you have this link:

<a href="www.altavista.com">Search</a>

and you want to capture the click change the link to:


<a href="/cgi-bin/redirect.pl?url=http://www.altavista.com">Search</a>


The script parses the query string variables where it finds the variable url which itdicates the url to which it should redirect the browser.  It uses the print "Location:" method of printing the MIME type header whcih redirects the browser...  This matains the final click to the external link within you web server log by "piping" it through the cgi... you get that last hit as a call to redirect.pl...
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
GorGor1Author Commented:
Ok, I can kinda follow the theory behind the script.  My final questions are:

If the page that contains the link needs to be followed is "www.site.com/index.cgi?1234" and the page to redirect to (to have the hit counted) is "www.site.com/page2.html", what do I substitute in the following line?

if (($fields{url} ne "") && ($fields{url} =~ /http:\/\//))

or do I leave the line "as is"?

Also, are these next lines required for the script to work?  Will they be automatically executed?  If I need them, with my example pages given above, what would I substitute in these lines?
-------
#Default if not found
open (LOG, ">>/virtual/ar/cgi-data/redirect.log");

print LOG "Error de syntax en $ENV{'HTTP_REFERER'}\n";

close LOG;

#default if all else fails
print "Location: http://www.xxx.com\n\n";

call like this

<a href="/cgi-bin/redirect.pl?
url=http://www.xxx.com">xxx</a>

--------

Thanks again

0
 
guadalupeCommented:
Forgive me as I'm short on time:

First quetion don't change anything the link is exactly as I explained The link you gave:

www.site.com/index.cgi?1234

is to get to the page... were talking about leaving the page, two completely different things...


This is just a error log which you can include as you which the only things to edit is the path to the log.  Don't worry if the file doesn't exist, as long as the path you give exists. perl will create the log file the first time it is called and append to it thereafter.

#Default if not found
open (LOG, ">>/COMPLETE_PATH/redirect.log");

print LOG "Error de syntax en $ENV{'HTTP_REFERER'}\n";

close LOG;


This code is a good idea.  That way if the script receives incomplete or bad info it won't just die but send the user to a default URL

#default if all else fails
print "Location: http://www.xxx.com\n\n";
0
 
GorGor1Author Commented:
Adjusted points to 75
0
 
GorGor1Author Commented:
I tried out the script and it seems to only be taking me to "http://www.site.com/index.cgi?1234" since I used the command "/cgi-bin/redirect.pl?url=http://www.site.com/index.cgi?1234".  I could have done this with the simple <body onload="window.location='http://www.site.com/index.cgi?1234';"> in javascript.

This is what I need to do:  
Once at "http://www.site.com/index.cgi?1234" (which is NOT on my server), I need the user to be redirected to "http://www.site.com/anotherpage.html" (in the same window) with site.com thinking that the user clicked on the appropriate link on the first page.  Is there a way to do this?  The redirect.pl script you gave me SEEMS to not be doing this.  How do I use perl to "follow links"?  Thanks again!

Tim
0
 
guadalupeCommented:
Ok yes there is a way to do this but what you want was not clear at first... This will take me a little more time... question do you know the second like you want to actually end up at or do you have to some how parse is out from
"http://www.site.com/index.cgi?1234" 
also do you have the module LWP installed or can you install moduals?

 
0
 
guadalupeCommented:
#!/usr/local/bin/perl


use LWP::Simple;

#set second url WITH http://
$url = "http://www.site.com/anotherpage.html";

#Get the first page, causing a hit
$index_list = get("www.site.com/index.cgi?1234");

#Go to second page
print "Location: $url\n\n";

exit(0);
0
 
GorGor1Author Commented:
Yes, I have LWP installed.  I'm not too sure what you are asking in your second question, but maybe this will explain it:

When you go to "http://www.site.com/index.cgi?1234", the page will have a LINK on it that goes to "www.site.com/nextpage.html".  the index.cgi is just using the variable "1234" to know that I am the one referring users to the index.cgi page of the site.  The link on "http://www.site.com/index.cgi?1234" needs to be followed (clicked) in order to count the hit to the site.

Will the script you gave me last completely replace the previous script?  Is it a fully functional script?

What does the line 'print "Location: $url\n\n";' do? Does it open a page in the same browser window?


P.S.  Thank you for all your help so far  :o)
0
 
guadalupeCommented:
Will the script you gave me last completely replace the previous script?  

YES

Is it a fully functional script?

YES

What does the line 'print "Location: $url\n\n";' do? Does it open a page in the same browser window?

This prints the MIME type header which redirects the browser to $url.  It does it in the same window.  If you want to do it in a new window then make the target of the link to this cgi a target="_blank" and presto its a new window.
0
 
GorGor1Author Commented:
Last and final quick question(s) and you get the points  :o)

the line '$index_list = get("www.site.com/index.cgi?1234");' will cause site.com to think that the user is being referred to "www.site.com/nextpage.html" by the page "www.site.com/index.cgi?1234"?

And also, to call the script, all I need is '<a href="/cgi-bin/redirect.pl">click</a>'?  I don't need to pass a variable to redirect.pl, right?  Thank you for all the help!  Points will be yours after I get your response!  :o)

Tim



0
 
guadalupeCommented:
the line '$index_list = get("www.site.com/index.cgi?1234");' will cause site.com to think that the user is being referred to "www.site.com/nextpage.html" by the page "www.site.com/index.cgi?1234"?

No this will make the site think someone is enetering:
www.site.com/index.cgi?1234

Then we capture the returned page in $index_list (stupid name for this context change to $html_page) After we capture the returned page we still have control (that is to say we havn't "returned" to the browser yet...)
The we send the location of were we really want to go with:

#Go to second page
print "Location: $url\n\n";




And also, to call the script, all I need is '<a href="/cgi-bin/redirect.pl">click</a>'?  I don't need to pass a variable to redirect.pl, right?

RIGHT!

Thank you for all the help!  Points will be yours after I get your response!  :o)
0
All Courses

From novice to tech pro — start learning today.