PDA

View Full Version : Perl / Javascript SSI Question


netroact
05-15-2006, 01:58 AM
I made a Perl script to get some environment variables from a javascript on an external server. Everything is fine, except the referrer url is
truncated in Google's querystring. Here is the Perl script:



#!/usr/bin/perl

use CGI;

my $query = new CGI;

my $referrer = $query->param('referrer');

open (DATABASE,">>TEST.txt");
flock(DATABASE, 2);
print DATABASE "$referrer\n";
flock(DATABASE, 8);
close (DATABASE);

exit;
1;




Here is the Javascript SSI snippet:



<script type="text/javascript">
document.write("<script type=\"text\/javascript\" src=\"http:\/\/somesite.com\/cgi-bin\/stats\/test.pl?" + "url=" + document.URL + "&" + "referrer=" + document.referrer + "\"><\/script>");
</script>




Here is the results:
http://www.google.com/search?hl=en

The results should have been:
http://www.google.com/search?hl=en&q=purdy+gurls

Anyone know why I'm not getting the full string? Any help would be appreciated.
?
?
?

mlseim
05-15-2006, 04:28 PM
It's the ampersand?

Try changing & to &amp;

.... ument.URL + "&amp;" + "referr ....

netroact
05-16-2006, 02:37 AM
It's the ampersand?

Try changing & to &amp;

.... ument.URL + "&amp;" + "referr ....


Thanks mlseim! You are always so helpful to me.

I was thinking maybe I had to backslash something. I guess asccii was the answer. It works, except now the + signs aren't showing up. The reason it matters is because it is used as a hyperlink in my scripts to go back to the exact referrer page on Google. I tried using the asccii for a + , which I can't seem to display on here either. Do you have any ideas on how to make the + show up in the url string? Even if I can't get the whole url string at least now I am getting the keywords.

I noticed that the real url string is longer today.

KevinADC
05-16-2006, 05:15 AM
You should be asking javascript questions in the javascripting forum.

netroact
05-16-2006, 05:20 AM
This is a perl question. The javascript parses the data just fine. The perl is having the problem parsing it.

FishMonger
05-16-2006, 05:40 AM
Perl is having a problem parsing it because the javascipt code is not formating it correctly. I can help on the perl side, but I'm not very good at javascript, so I may not be able to help in correcting the javascript code so that perl can properly parse it.

KevinADC
05-16-2006, 07:05 PM
This is a perl question. The javascript parses the data just fine. The perl is having the problem parsing it.


OK, if you say so, it must be true. ;)

mlseim
05-16-2006, 07:19 PM
How about building it all up with a string ...

$string=""http:somesite.com\cgi-bin\stats\test.pl?+url=document.URL&+referrer ..."; (or whatever) ...

Then using that string in your print statement?

That would let you create the whole URL without escaping things.

just a thought ...

netroact
05-16-2006, 11:52 PM
How about building it all up with a string ...

$string=""http:somesite.com\cgi-bin\stats\test.pl?+url=document.URL&+referrer ..."; (or whatever) ...

Then using that string in your print statement?

That would let you create the whole URL without escaping things.

just a thought ...


The emailer musta farted on this thang again. I didn't get an instant notification when yall posted.

I don't understand how to apply what you're saying. It seems to me that you are illustrating how to read it into a Perl variable. That would have to take place after Perl already parsed it wrong.

Maybe I could read it into a javascript variable. I have an idea. Maybe I could ask that over in the javascript forum. :)

You know what they're gonna say though: You need to ask that in the Perl forum.

Just watch.

mlseim
05-18-2006, 01:17 PM
... and oh my ... I should bite my tongue ... is there perhaps a PHP method?

FishMonger
05-18-2006, 02:51 PM
Try this:
<script type="text/javascript">

var ssilink = "http://somesite.com/cgi-bin/stats/test.pl?url=document.URL&ampreferrer=document.referrer";

// print the link to verify its syntax
document.write(ssilink);

document.write("<script type='text/javascript' src=ssilink></script>");
</script>


I'm not sure if document.URL will get interpolated within the string. You may need to concatenate it.

var ssilink = "http://somesite.com/cgi-bin/stats/test.pl?url=" . document.URL . "&ampreferrer=" . document.referrer;

FishMonger
05-18-2006, 03:54 PM
... and oh my ... I should bite my tongue ... is there perhaps a PHP method?
There's a php method, and an asp method, and a C# method, and a perl method, but everyone of those "methods" relies in fixing the javascript code.

netroact
05-19-2006, 12:19 AM
It seems to like your 2nd example best, Fishmonger, but it stills gives me an error that says, "expected identifier" right where the quotation marks are located just before the ampersand. I think that error is used when someone tries to use a reserved or unacceptable variable name. I don't understand why it would call that error at that character.

I appreciate your efforts on this, because I am clueless, and I know there is a solution.

netroact
05-19-2006, 12:22 AM
... and oh my ... I should bite my tongue ... is there perhaps a PHP method?

:confused:

mlseim
05-19-2006, 03:02 AM
Netroact ... I sometimes get carried away with PHP stuff on the Perl forum.

It's just that beginners sometimes have so many problems with the cgi-bin
concept, ASCII upload, CHMOD, modules, etc .... that I just throw a simple
PHP script at them that does the simple task they need. They can upload it
into their main directory the same as they do images and it works for them.

So when I can't get them to understand the Perl concept, I try to throw them the PHP bone ... So I snickered when I mentioned PHP.

Look at the variations of threads, questions, and problems people have with
just simple form processing ... I think we should start a sub-forum on Perl
just for that topic alone (like a tutorial).

Some questions on this forum do get strange ...

netroact
05-19-2006, 03:21 AM
Yea I know. I've read some of your posts on PHP before. I was jokin :D

I actually have some PHP scripts. I messed around with it for awhile, but in the end I still think Perl is a lot more fun. :thumbsup: