Submit Your Article Forum Rules

Results 1 to 5 of 5

Thread: Need PHP to Perl Support

  1. #1
    WebProWorld MVP Webnauts's Avatar
    Join Date
    Aug 2003
    Location
    European Community
    Posts
    9,028

    Lightbulb Need PHP to Perl Support

    Can some translate these PHP lines into Perl?

    PHP Code:
    <?php
    if (strstr($_SERVER['REQUEST_URI'], '?') || strstr($_SERVER['REQUEST_URI'], '&'))
    {
        
    header('X-Robots-Tag: noindex,noarchive,nosnippet');
    }
    ?>
    Thanks in advance,

    John

  2. #2
    WebProWorld MVP danlefree's Avatar
    Join Date
    Jun 2005
    Posts
    414

    Re: Need PHP to Perl Support

    Haven't tested, but the following would probably be a good start if you're primarily concerned with preventing pages with GET variables from appearing in search results:

    Code:
    if ( "" != $ENV['QUERY_STRING'] ) {
        print "X-Robots-Tag: noindex,noarchive,nosnippet";
    }
    ... or ...

    Code:
    use CGI;
    
    $q = new CGI;
    @q_param = $q->url_param;
    if ( $#q_param != -1 ) {
        print "X-Robots-Tag: noindex,noarchive,nosnippet";
    }
    Dan LeFree | Owner/Operator (Web development, marketing)

  3. #3
    WebProWorld MVP Webnauts's Avatar
    Join Date
    Aug 2003
    Location
    European Community
    Posts
    9,028

    Re: Need PHP to Perl Support

    Dan I am not sure if you got my point.

    I want to block URLs including a "?" and "&".

  4. #4
    WebProWorld MVP danlefree's Avatar
    Join Date
    Jun 2005
    Posts
    414

    Re: Need PHP to Perl Support

    Quote Originally Posted by Webnauts View Post
    Dan I am not sure if you got my point.

    I want to block URLs including a "?" and "&".
    The code samples should have caught any requests which included a query string (which seemed to be a more elegant implementation - best to avoid substring comparisons if possible). Tested both and they definitely didn't work as intended...

    Try:

    Code:
    if (
        $ENV{'REQUEST_URI'} =~ m/\&/ ||
        $ENV{'REQUEST_URI'} =~ m/\?/
    ) {
        print "X-Robots-Tag: noindex,noarchive,nosnippet";
    }
    (Tested and confirmed working)

    Update: ... and here's a working implementation of the CGI GET parameter count if it will be sufficient to simply determine whether GET variables have been set:

    Code:
    use CGI;
    $q = new CGI;
    if ( $q->url_param > 0 ) {
        print "X-Robots-Tag: noindex,noarchive,nosnippet";
    }
    Dan LeFree | Owner/Operator (Web development, marketing)

  5. #5
    WebProWorld MVP Webnauts's Avatar
    Join Date
    Aug 2003
    Location
    European Community
    Posts
    9,028

    Re: Need PHP to Perl Support

    Thank you very much Dan. I will try those out!

Similar Threads

  1. PERL pass "Perl" crash
    By TrafficProducer in forum Web Programming Discussion Forum
    Replies: 0
    Last Post: 09-02-2007, 02:07 PM
  2. Perl, CGI and SSI
    By dak888 in forum Web Programming Discussion Forum
    Replies: 2
    Last Post: 02-27-2007, 11:16 AM
  3. Cox.com/support > Customer Support GUI
    By mars6263 in forum Submit Your Site For Review
    Replies: 1
    Last Post: 06-29-2004, 10:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •