Welcome to WebmasterWorld Guest from 54.196.224.166

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Convert PHP scripts to Perl

Convert two little PHP scripts to Perl

     

Webnauts

3:36 pm on Mar 10, 2009 (gmt 0)

5+ Year Member



I have two PHP scripts which I would love to have them in a Perl version:

<?php
if ($_GET["bots"] == "nocrawl") {
$find = array
(
"&bots=nocrawl",
"?bots=nocrawl"
);
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.example.com".str_replace($find, '', $_SERVER['REQUEST_URI']));
}
?>

and

<?php
if (!stristr($_SERVER['HTTP_USER_AGENT'], 'googlebot')) {
echo '<p class="optout"><a href="/mailing-list/index.php" title="Opt-out">Unsubscribe Newsletter</a>.</p>';
}
?>

can someone help me please?

Thanks a lot in advance.

[edited by: eelixduppy at 1:28 am (utc) on Mar. 11, 2009]
[edit reason] switched to example.com [/edit]

janharders

9:52 am on Mar 13, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I don't have any way to test that right now but this should do it:

<?php
if ($_GET["bots"] == "nocrawl") {
$find = array
(
"&bots=nocrawl",
"?bots=nocrawl"
);
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.example.com".str_replace($find, '', $_SERVER['REQUEST_URI']));
}
?>

perl version


#/usr/bin/perl -w
use strict;
use CGI;
my $CGI = new CGI;
if($CGI->param('bots') eq 'nocrawl')
{
my $uri = $ENV{'REQUEST_URI'};
$uri =~ s/[&?]bots=nocrawl//i;
print "HTTP/1.1 301 Moved Permanently\n";
print "Location: http://www.example.com" . $uri . "\n\n";
}

-------

<?php
if (!stristr($_SERVER['HTTP_USER_AGENT'], 'googlebot')) {
echo '<p class="optout"><a href="/mailing-list/index.php" title="Opt-out">Unsubscribe Newsletter</a>.</p>';
}
?>

perl version


#/usr/bin/perl -w
use strict;
if($ENV{'HTTP_USER_AGENT'} !~ m/googlebot/i)
{
print '<p class="optout"><a href="/mailing-list/index.php" title="Opt-out">Unsubscribe Newsletter</a>.</p>';
}