homepage Welcome to WebmasterWorld Guest from 54.226.180.223
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Convert PHP scripts to Perl
Convert two little PHP scripts to Perl
Webnauts




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

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




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

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>';
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved