Hello,

I'm near completing my little module for our project, but have run into something I'm not sure how to handle.

Project specs.
Client comes to website\s the module authenticates by checking IP against a central Database. IF the IP is not allowed to access we redirect them to a login page. If the IP is cleared to view the site then they need to be allowed to see the site.

The issue I’m having

Where the client’s IP is cleared to see the website, if I use a redirect I fall into a endless loop but I can’t seem to find any other method to do this. I would also like them to go directly to the page they are trying to reference.


Here is the code I have

package Apache2::Authclients;
use strict;
use DBI;
use CGI qw(:standard);
use Apache2::Connection ();
use Apache2::RequestRec (); # for $r->content_type
use Apache2::RequestIO (); # for $r->puts
use Apache2::Const -compile => ':common';
sub handler {
my $r = shift;
my $product = $r->dir_config('product');# Grab Var From Dir on which site
my $uri = $r->uri(); #incoming URL
my $c = $r->connection();
my $time = scalar localtime();
my $remote_sa = $c->remote_ip(); # icoming IP
my $result = &check_ip($remote_sa, $product); # Call to check for access 0 = NO 1 =YES
if ($results == 1) {
$r->content_type('text/html');
$r->puts(<<END);
<HTML><HEAD><meta http-equiv="REFRESH" content="0";url=" . $uri . """></HEAD><BODY></BODY></HTML>
END
return Apache2::Const::OK;
}
else
{
$r->content_type('text/html');
$r->puts(<<END);
<HTML><HEAD><meta http-equiv="REFRESH" content="0;url=<some URL> "></HEAD><BODY></BODY></HTML>
END
return Apache2::Const::OK;
}
}

In reply to Apache2 Mod_perl 2 without a endless loop of redirect by overworked

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.