We help IT Professionals succeed at work.

forcing a 'hit'

GorGor1
GorGor1 asked
on
258 Views
Last Modified: 2010-03-05
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;


Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

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
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...

Author

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

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";

Author

Commented:
Adjusted points to 75

Author

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
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?

 
#!/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);

Author

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)
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.

Author

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



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)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.