Click to See Complete Forum and Search --> : getting name of file on a link


druss
12-09-2003, 09:17 PM
i am supplied with a link and what i want to do is get rid of all the http:// stuff and only have the file name.

For example i get the links from using HTML::LinkExtor

i end up getting the link http://test.com/file.zip
i need to keep the whole link and put just file.zip into a variable.

so far i am think that a simple split would work and just get the last array but i cant seem to make it work.

any help is appreciated.

Thanks
Goran

Jeff Mott
12-09-2003, 10:41 PM
Probably better to use URI::URL since it decodes the URL, and makes considerations for attached query strings and fragments.use URI::URL();
my $url = URI::URL->new($str);
print +($url->path_segments())[-1];

druss
12-10-2003, 08:56 PM
Thanks for that.
i figured ill post another problem in here to stop another thread being created.

the problem is ofcourse that when i get the input from checkboxes i get a space infront of the values.

for example i would have three random checkboxes created by the script all with the same name called 'add_selected_links' but all with different values.

this is how i get my input:

sub parse_input {
@selected_links = ();
$i = 0;
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $slot (@pairs) {
($name, $value) = split(/=/, $slot);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\s+$//;
if($name eq "selected_links") { $selected_links[$i] = "$value\n"; $i++; }
else {
$$name = $value;
}
}
}

the problem is that when i print @selected_links into a text document i get the following results:

http://test.com/services.htm
http://test.com/services.htm
http://test.com/privacy.htm

(it doesnt show the space in front of the second and third link but there is a single space infront of it and not infront of the first link)

as you can see there is a space in front of the values after the first one.

Can you please tell me why its doing this, and how to fix it.

Thanks again,
Goran

Jeff Mott
12-10-2003, 09:49 PM
I don't see anything in the parse_input routine that would cause it. It could be happening when it is being printed. Also make sure you have not modified the $, (output field separator) variable.

And also, note that with the parse_input you have now, I could change that variable within the program by submitting a form with a name of "," and a value of whatever I want it to be. I could set any variable to any value I want it to be, which is a security risk. It is a far better idea to use the CGI module to parse the form input for this and many other reasons.

druss
12-11-2003, 01:28 AM
hmm, i guess your right. the thing is that i have put the code that doesnt let anybody use the script unless it on my server.

for example its something like:
unless($referer =~ "http://leechbuster.com") { command }
&quit;


its something like that but i took it off so that i could test the script on my computer.

so i guess my question is that is it still a security problem even with the code above, and if so what is the cgi module called so that i may get it. :)

Thanks alot for your time
Goran

Jeff Mott
12-11-2003, 01:38 AM
so i guess my question is that is it still a security problem even with the code aboveYes, because the referrer is information provided by the client's computer. So someone who knows what they are doing could send a false referrer. In other words they can make your script think it came from your server whether it really did or not.what is the cgi module calledCGI.pm ;) use CGI;
my $cgi = CGI->new();
print $cgi->param('selected_links');http://www.perldoc.com/perl5.8.0/lib/CGI.html