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?
Re: Adding sessionid to all links in HTML-document
by perrin (Chancellor) on Feb 23, 2009 at 22:25 UTC
|
Take a look at some of the prior art:
Also, consider the classic trick of putting the session ID first in the path and using relative URLs:
http://example.com/123456789/path/to/doc.html
| [reply] [d/l] |
Re: Adding sessionid to all links in HTML-document
by Your Mother (Archbishop) 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.
| [reply] [d/l] [select] |
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.
| [reply] |
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.
| [reply] |
|