Forum Moderators: coopster & phranque

Message Too Old, No Replies

CGI script and URL capture

URL capturing

         

erenshte

1:30 am on Apr 27, 2004 (gmt 0)

10+ Year Member



Guys,

Here is my problem. I have developed site where user
will be able to capture URL of pages he is visiting and save the URL and some additional information in a
database. I have developed script that generates a form. This form contains several text fields, one of them is URL adedress of the page user is visiting.
This script resides on my server and is accessable from Favorites or Links in IE, or Bookmarks in Netscape. I would like to capture URL, save it in a variable, let say $url, and then use this variable to
set a value for the text field in the form.

jdMorgan

2:22 am on Apr 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



erenshte,

Welcome to WebmasterWorld [webmasterworld.com]!

This works on Apache to get the requested URI:


$uri = "$ENV{'REQUEST_URI'}";

Jim

erenshte

2:41 am on Apr 27, 2004 (gmt 0)

10+ Year Member



Thanks, I'll try

erenshte

2:54 am on Apr 27, 2004 (gmt 0)

10+ Year Member



Jim,

This puts words REQUEST URL into text box.
I need to capture URL of the current page
and place it into this text box.

jatar_k

3:04 am on Apr 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld erenshte,

take a look here
[perl.about.com...]

jdMorgan

3:08 am on Apr 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's U R I, not U R L, and make sure you have the PERL environment variable support module loaded.

That came straight out of working code, but your server set-up may be different.

<added> I found a slightly different version, which might work for you:
my $uri = $ENV{DOCUMENT_URI};
</added>

Jim

erenshte

3:32 am on Apr 27, 2004 (gmt 0)

10+ Year Member



Thanks for clarification.
I'll let you know if it works.

erenshte

erenshte

4:08 am on Apr 27, 2004 (gmt 0)

10+ Year Member



Jim,

No one works. Now I'm double checking if Perl envirinment variable support module is loaded to the server I'm using. In your first suggestion,
'REQUEST_URI' is shown in the text box. In the
second one, the box remains blank.

Roman

jdMorgan

4:15 am on Apr 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the first case, I included the variable itself in a print statement. You should remove the double quotes if you are including the string itself inside a print statement, like the second example. The two should be equivalent, and return the same value, but one might work on your system while the other doesn't.

I just got done working on a PERL 'rename file' problem, and support for PERL across many systems is not at all consistent. You should provide a fallback in your code in case that variable returns null - You may have to ask the user to cut-n-paste from the address bar in that case, or use client-side scripting to fill it in.

Jim

erenshte

3:14 pm on Apr 27, 2004 (gmt 0)

10+ Year Member



Jim,

Cut-and-paste doesn't work for me because my site should work for dumm users. Client-side script may
help, but I want to avoid any installations on user's
computer for the same reason. This is why I decided
to create a bookmarklet (a link that runs a program
that resides on my server and runs on the browser).
It first should grab url and then create a form
with this URL in, then user adds some other information reqired and on submit all data are sent to database. I tried to use JavaScript: it works with
new blank window, but doesn't with the form stored on
the server because of JavaScript self-domain security issue. I'll try what you are suggesting and will let you know. So, I'm trying $uri = $ENV(REQUEST_URI);
right?

Many thanks and regards, Roman

erenshte

5:02 pm on Apr 27, 2004 (gmt 0)

10+ Year Member



Jim,

I have wrote a small script that checks all environment variables keys and values on my ISP's
server and I cannot find REQUEST_URI and DOCUMENT_URI there.

Here is the script:

#!c:\perl\bin
#env.pl
print "Content-type: text/plain\n\n";

while (($key, $value)=each(%ENV)){
print "$key = $value\n"; }

What does it mean?

Roman

erenshte

6:43 pm on Apr 27, 2004 (gmt 0)

10+ Year Member



Jim,

Do you know what my ISP should do to be able to
support these environment variables?

Another solution and question: I can capture
URL using very simple JavaScript. How can I pass
the variable that contains URL to my CGI script?

Roman

erenshte

3:02 am on Apr 30, 2004 (gmt 0)

10+ Year Member



Jim,

I have solved the problem, using QUERY_STRING variable
that captures value passed to the CGI script.
I have developed small javascript, see below:

javascript: void(open('http://www...../captureurl.pl?'+location.href; new window properties go here))

At the top of captureurl.pl file I put

my $url = $ENV{QUERY_SCRIOPT};

Thanks for your help.

Roman

jdMorgan

3:11 am on Apr 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm glad you got it working... I just checked in, and I see that I missed several of your posts. I'm far from an expert on PERL, so I don't know why I can access the {REQUEST_URI} variable and you cannot -- probably some PERL configuration option that I don't know about.

Jim

erenshte

2:00 pm on Apr 30, 2004 (gmt 0)

10+ Year Member



Thanks, Jim

I don't understand why MS Server doesn't support all
ENV variables. You were right, REQUEST_URI is supported only in Apache. Buy the way, my ISP is
willing to set it up. There is a typo in my previous
message (QUERY_STRING)

Roman