Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

info from one page to another.

by Granite (Initiate)
on Dec 31, 2000 at 18:48 UTC ( #49097=perlquestion: print w/ replies, xml ) Need Help??
Granite has asked for the wisdom of the Perl Monks concerning the following question:

This has been puzzling me for ages. I have some info on the first page (start.cgi) like:
$cinfo = "Granite";
$pword = "something";
$pinfo = "Im Tall";

and I need to get this info on to another page (start2.cgi).
On some site i've seen the URL as:
http://www.blah.com/something.cgi?cinfo=Granite&pword=something

Also I've spoken to some people and they meantion hidden form fields but then they logged off and didn't tell me how to use them.

Could you please help me.

Granite

Comment on info from one page to another.
Select or Download Code
Re: info from one page to another.
by Trimbach (Curate) on Dec 31, 2000 at 19:59 UTC
    What you want to do is save "state" from one invocation of your CGI to the other. There are several ways to do this, with different pros and cons... Merlyn has an excellent node on this called Adding "state" to HTTP. Read and enjoy...

    Gary Blackburn
    Trained Killer

Re: info from one page to another.
by lolindrath (Scribe) on Dec 31, 2000 at 21:40 UTC
    This is what I usually do to pass additional information to the script. This is usually stuff that a user entered before (like user name and password ).
    <form method="post" action="./yourscript.pl"> <input type="hidden" name="cinfo" value=$cinfo> </form>

    Hope this helps.

    --=Lolindrath=--
      Thanks.

      So how would I get this to come up on the next page? Would it just be:

      print "$cinfo";???
        Ok, now I see what you're asking.
        <form method="post" action="./yourscript.pl"> <input type="hidden" name="cinfo" value=$cinfo> <input type="Submit"> </form>
        Ok, when you hit the submit button in the browser then you get the values you sent by doing this:
        # Look this Package up on Perlmonks to learn more about it use CGI qw/:standard/; my $Query = new CGI; # Get the parameter from the Query string by the name of # the field my $cinfo = $Query->param('cinfo'); print $Query->header(); print $cinfo;


        --=Lolindrath=--
Re (tilly) 1: info from one page to another.
by tilly (Archbishop) on Jan 01, 2001 at 02:19 UTC
    One warning. While what you ask is very easy to do, passing passwords in plain text makes for easily cracked websites. You should take that into account in your final solution.
Re: (fongsaiyuk) info from one page to another.
by fongsaiyuk (Pilgrim) on Jan 01, 2001 at 11:34 UTC
    In addition to passing hidden form elements between pages and potentially employing some of merlyn's above mentioned techniques, you might consider session management through the use of Apache::Session.

    Granted this is a server-based session-management solution and requires the installation of Apache webserver and mod_perl (optionally MySQL or PostgreSQL), so YMMV.

    Just throw in a Web application development framework like HTML::Mason or Text::Template and you too could be the next amazon.com!!!! :) see princepawn's node for some framework starting points...

    <tip>When using server-based session management, instead of storing lots of user data in the session consider storing only the row id from the user's login profile in the session. That way with one quick query to the database on a page reload you have all the user profile information. There are of course pros and cons to this, but for some applications such a technique would be desirable. </tip>

      <tip> When using server-based session management, instead of storing lots of user data in the session consider storing only the row id from the user's login profile in the session. That way with one quick query to the database on a page reload you have all the user profile information.</tip>

      This tip is particularly important to bear in mind if you're at all security conscious. It isn't particularly hard to manipulate session data, whether it's munged in the URL, or in a cookie, or wherever. If the only piece of information there is an ID that points to the real data, it's a lot harder to set that data.

      This of course means that you shouldn't use autoincremented values for this ID, unless you don't mind someone deciding that they'd rather be user 123143 instead of 124124.

      I've come across quite a few major ecommerce websites (including large public companies) who had URLs along the lines of http::www.wherever.com/cgi-bin/view_return?id=1233 to let you see the details of your return, and who would quite happily let you see the details of return 1232, 1231 etc as well...

      Tony

Re: info from one page to another.
by runrig (Abbot) on Jan 01, 2001 at 12:02 UTC
    Keeping in mind tilly's warning above...
    Using CGI.pm, the parameters are 'sticky', so if you have parameters 'cinfo' and 'pword' from the first page, just do this while printing the second page (inside whatever form they need to be in):
    print hidden('cinfo'),hidden('pword'); # Or in OO style: my $q = CGI->new; print $q->hidden('cinfo'), $q->hidden('pword');

Log In?
Username:
Password:

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

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

    The best computer themed movie is:











    Results (238 votes), past polls