You could use an array to store a list of all page views.
Store it in the url (or as a hidden field) as a single param,
?history=view1,view2,view3
Then when the script is invoked, turn this param into an array.
my ($q, %param, @history);
use CGI;
$q = new CGI;
%param = $q->Vars;
if (defined $param{history}) {
@history = split(',', $param{history});
}
Now you have a
@history array which lists all previous 'pages' viewed.
To add another onto the end
(which you must do to keep the list updated for every view.) you could do something like,
push @history, $param{view_page}
And make sure you add the updated history list back to the url (or hidden field) for every link in the new page you display.
my $history = join(',', @history);
my $page1url = $q->url(-absolute=>1)
. '?history='
. $history&view_page=view1;
my $page2url = $q->url(-absolute=>1)
. '?history='
. $history&view_page=view2;
The examples above are just to explain the theory. Listen to the above advice by
charnos and
rdfield regarding wider application design, and at the very least make sure you TAINT check the input before doing
anything with it.
You'll also have to think about things such as,
if the user follows a link you create named 'back' from View3 to View2, you'll have a list like this
view1,view2,view3.
Do you then add view2 to the end, giving you
view1,view2,view3,view2?
or do you
pop view3 off, giving you
view1,view2?
This kind of stuff can get messy real fast, so plan well!
If you're going to use this to force users along a certain route, that's ok (?!), but if you want to provide back links, here's an article by
Abigail which explains why back links with HTML and CGI generally don't work, you'll find it here,
http://www.foad.org/~abigail/HTML/Misc/back_button.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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.