Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Adding sessionid to all links in HTML-document

by planet (Initiate)
on Feb 23, 2009 at 21:35 UTC ( #745841=perlquestion: print w/ replies, xml ) Need Help??
planet has asked for the wisdom of the Perl Monks concerning the following question:

I need a quick, fast and reliable solution to add a sessionid to each html-tag-attribute (a, form, img, iframe, etc.) in a HTML-document.

There are solutions with regex´s, but they are too slow for my needs (50-200kbytes HTML-documents).

I need a solution, that´s capable of doing this in 50-100ms per document (each doc with 100-400 affacted tags).
This maybe done in XS only?

Comment on Adding sessionid to all links in HTML-document
Re: Adding sessionid to all links in HTML-document
by Your Mother (Canon) on Feb 23, 2009 at 21:49 UTC

    Your question is a little vague. Do you mean adding it to every tag? Like <i sessionid="asdf"/>? Because that would be invalid HTML. Or add it to the arguments in src like attributes, like <form action="...?sid=asdf"/> and <a href="...?sid=asdf"/>?

    Either way the solution is almost certainly based off a parser like HTML::TokeParser. HTML is better handled (accuracy and speed) by parsers for anything robust. If you provide more info or show what you've tried, you'll probably get a decent snippet or two here.

Re: Adding sessionid to all links in HTML-document
by perrin (Chancellor) on Feb 23, 2009 at 22:25 UTC
Re: Adding sessionid to all links in HTML-document
by skx (Parson) on Feb 23, 2009 at 22:29 UTC

    I suspect the most pragmatic approach here might be to change your session-management to use cookies.

    Outputting a cookie with session ID in it has got way way less overhead than having to output each file with changed contents.

    Failing that you might want to look to see if there is an Apache module that would let you do what you want. There are certainly output filters which can modify the output the server sends after generation - and that would be a good hook to use.

    Steve
    --
Re: Adding sessionid to all links in HTML-document
by Anonymous Monk on Feb 24, 2009 at 08:39 UTC
    There are solutions with regex´s, but they are too slow for my needs (50-200kbytes HTML-documents).
    Pleas show your benchmark code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://745841]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-08-27 16:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (244 votes), past polls