Below works like a charm, thanks for the idea!
Now two questions more come to mind :
1 - would url() work faster than self_url() since it doesn't have to use the query string or is url() fetched by taking self_url() and cutting it down, IE more steps?
2 - Is there any way to shorten/speed/improve this way?

Thanks!

Dan

### http_prot code that works ###

#!/usr/bin/perl -w

use strict;
use warnings;

use URI;
use CGI ':standard';

#my $uri = new URI(self_url());
#my $http_prot = $uri->scheme;
# these two together worked but this works too and is one line

my $http_prot = new URI(self_url())->scheme;

print header;
print "-$http_prot- \n";

############

Toby Stuart wrote:


-----Original Message-----
From: Dan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 23, 2003 1:19 PM
To: [EMAIL PROTECTED]
Subject: finding protocal script is called with


Hello, here's one for you all.

What is the fastest way to find out what protocal a script is being called from ?
IE http, https, ftp ,etc

currently I have to use :

sub set_prot {

use CGI self_url;
$self_url_query = CGI::new();
$self_url = $self_url_query->self_url();

if($self_url =~ m/^https\:\/\//i) { $http_prot = 'https'; }
else { $http_prot = 'http'; }

return $http_prot;
}
I know there's got to be a better/faster/shorter way

Mainly interested in http and https so that generated html can be like this :

<img src="$http_prot\://domain.com/images/pic.png">
That way if the page is access via http
<img src="http://domain.com/images/pic.png";>
but if it's accessed via https it's
<img src="https://domain.com/images/pic.png";>

And then you won't get the not so good "not all items on this page are secure" bit.

Any ideas?


Try the URI module eg.
Just load your URL into a new URI object and then look at the 'scheme'

use strict;
use warnings;

use URI;

my $url = new URI('http://www.someplace.com/');
#my $url = new URI('https://www.someplace.com/');
#my $url = new URI('ftp://www.someplace.com/');

print $url->scheme;




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to