CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
full path and virtual path

 



Wild_Thing
stranger

Oct 11, 2001, 2:33 AM

Post #1 of 4 (633 views)
full path and virtual path Can't Post

I have guestion about perl-CGI.
Let's say I have cgi script in the cgi-bin folder (really dosnt matter where it is). And I have web page that calls this skript out with GET. Now I can get HTTP_REFERER (http://www.server.com/user/folderx). But that I need, is full path of this web page. I can get it's virtual path (/user/folderx) but how i can get it's full path (/home/user/www/folderx/).



rGeoffrey
User / Moderator

Oct 11, 2001, 11:14 AM

Post #2 of 4 (628 views)
Re: full path and virtual path [In reply to] Can't Post

Look at these parts of %ENV...

$ENV{SERVER_NAME}
$ENV{SCRIPT_NAME}
$ENV{DOCUMENT_ROOT}

By adding SCRIPT_NAME or HTTP_REFERER to SERVER_NAME you get a complete URL.
By adding SCRIPT_NAME or HTTP_REFERER to DOCUMENT_ROOT you get a complete filename.




Wild_Thing
stranger

Oct 12, 2001, 5:47 AM

Post #3 of 4 (619 views)
Re: full path and virtual path [In reply to] Can't Post

Thanks, but I didn't get help :(

Information that I got was:
DOCUMENT_ROOT = /var/www/html
HTTP_REFERER = http://www.vaip.werro.ee/elvar/katsed/
REQUEST_URI = /cgi-bin/variables.cgi?pppp
SCRIPT_FILENAME = /var/www/cgi-bin/variables.cgi
SCRIPT_NAME = /cgi-bin/variables.cgi
SERVER_NAME = www.vaip.werro.ee

SERVER_SOFTWARE = Apache/1.3.19 (Unix) (Red-Hat/Linux) mod_perl/1.24

Full path to the page that called script out is
/home/elvar/public_html/katsed
but i cannot get this information out using %ENV variables.



rGeoffrey
User / Moderator

Oct 12, 2001, 2:32 PM

Post #4 of 4 (613 views)
Re: full path and virtual path [In reply to] Can't Post

This is closer to what you want...


Code
my %ENV = (HTTP_REFERER => 'http://www.vaip.werro.ee/elvar/katsed/', 
SERVER_NAME => 'www.vaip.werro.ee',
);
$ENV{HTTP_REFERER} =~ m|$ENV{SERVER_NAME}/(.*)|;
my @parts = split ('/', $1);
my $user = shift @parts;
my $file = join ('/', "/home/$user/public_html", @parts);
print $ENV{HTTP_REFERER}, "\n";
print $file, "\n";

And in answer to your other question, you need to make sure that "home/$user" exists...


Code
print "the file does exist\n" if (-e $file);

There are a great many other file checks like -d for directory that might also be useful.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives