SPUG: Trapping Named Anchor References

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Mon Oct 9 14:23:11 CDT 2000


> 
> > I need to capture a named anchor reference for a redirect.
> 
> Story line:
> A user clicks on a saved link or a link in an email like:
> 
> http://www.myserver.com/cgi/coolsite.pl?page=124#item16
> 
> but the coolsite.pl script notices the user doesn't have a logged-in cookie so
> it displays a log-in page rather than the requested content page. Fine so far.
> 
> The user fills in UserID and Password and clicks on Submit. The form action
> specifies the log-in script which verifies the users info and then does a
> re-direct to the url the user originally wanted to see (which still appears in
> its entirety in the browser Location box) to be displayed by the normal display
> script.
> 
> Everything works fine except the named anchor reference.
> 
> Here's the problem: I can find no way to trap the '#item16' portion of the url.
> I need that in order to compose the complete URL for the 'Location:' header so
> the user does not end up confused to find themselves at the top of a long page
> when they really want to see an item farther down.
> 
> On Linux/Apache, the anchor ref does not appear anywhere in %ENV
> 
>   You can check this at:
>   http://caucus.bigmindmedia.com/cgi-dv/showenv.pl?data=123#AnchorRef
> 
> Not surprisingly then, I can find no tool in CGI.pm to grab it.
> 
> My searches of the likely archives have come up dry.
> 
> Lest you suggest integrating the User Verification into the main script, I
> should mention that one purpose of the redirect is to avoid the 'Resubmit Form
> Data' problem.
> 
> My best solution is redundancy: Always dup the anchor ref in the query string.
> Thus:
> 
> http://www.myserver.com/cgi/coolsite.pl?page=124&anch=item16#item16
> 
> This allows me to handle any link the user may have saved and to rebuild the
> anchor ref from the query string during log-in. It's not exactly normalized but
> it does the job. <g>
> 
> Any suggestions?
> 

Perhaps URI would help... ?

use URI;

my $uri = "http://caucus.bigmindmedia.com/cgi-dv/showenv.pl?data=123#AnchorRef";

my $u = URI->new($uri);

print $u->fragment;   # AnchorRef
__END__


--
Charles DeRykus

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list