Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
USE USERNAME FROM LOGIN FORM TO THE 3rd PAGE WEB ?

Posted by muroo_08 (muroo_08), 16 July 2007
i have a problem to pass username login to the 3rd page after checklogin.pl :
this is the part of the checklogin.pl script (to read login.pl):
...
...
foreach $pair (@pairs)
{
   ($name, $value) = split(/=/, $pair);
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;  
   $value =~ s/~!/ ~!/g;

   $FORM{$name} = $value;
   if ($value =~ /\<\!--\#(.*)\s+(.*)\s?=\s?(.*)--\>/) { &kill_input; }
   if ($value =~ /[;><\*`\|]/) { &kill_input; }
}

open (FN,"checking.cfg");
@usercheck= <FN>;
close FN;
chomp (@usercheck);

foreach (@usercheck) {
 if ($_ !~ /^#|^ |^\;/ ) {
    ($username,$password) = split (",",$_);
    chomp ($username);
    chomp ($password);
   
    if ($FORM{'username'} eq $username && $FORM{'password'} eq $password) {
      if ($username eq "Admin") {
...
...
print "<FRAMESET ROWS=31%,*>\n";
   print "<FRAMESET COLS=55%,*>\n";
   print "<FRAME NAME=leftpage SRC=left.pl >\n";
   print "<FRAME NAME=righpage SRC =linkpage.pl >\n";
   print "</FRAMESET>\n";    
   print "<FRAME NAME=OUTPUT SRC=out.pl>\n";  
print "</FRAMESET>\n";
...
...

THEN:
and the third page, i want to use the username for    left.pl , the page contain TABLE with VALUE is the username, but when i try, the VALUE IS BLANK

? thanks, hope u reply (sorry for bad english) ?




Posted by admin (Graham Ellis), 16 July 2007
Your English is a lot better than my Indonesian  

Web pages / the common gateway interface that you're using are "stateless" - in other words, each request (i.e. page or frame) stands on its own WITHOUT having the data from the previous request available to it.  It starts afresh if you like to think of it that way.

In order to pass data from one page to another, you need to "maintain state". The most common way to do this on larger applications is to use cookies, but you can also use hidden fields on a form or add extra information on to the end of a a URL.   Each of these is a big subject; there's further reading / examples here on our website and a very great deal of information elsewhere too - for example here in the Web Developers Library.

Passing just a single, simple parameter can be much easier - if you replace
print "<FRAME NAME=leftpage SRC=left.pl >\n";
by
print "<FRAME NAME=leftpage SRC=left.pl?username=$FORM{username} >\n";
then you'll be able to collect your user name in your left.pl script that generates your left hand frame.

Posted by muroo_08 (muroo_08), 16 July 2007
hi graham, i'm sorry before because i'm still beginner with this.
about ?username=$FORM{username},
then to the output.pl, i write  $username but still doesn't work, and why you use
?username=$FORM{username}  not
$username=$FORM{'username'}




Posted by admin (Graham Ellis), 16 July 2007
The single quotes are optional - it will work with them and it will work without them.

There's no $ on the "username" because you want the literal text 'username' to be a part of the URL at this point - you're saying to the next page that the username parameter has the value that's in the hash called %FORM.

Posted by muroo_08 (muroo_08), 16 July 2007
 
sorry bother again, i have tried use:
<FRAME NAME=leftpage SRC=left.pl?username=$FORM{username} >, and the third page the part script like this :

#!/usr/bin/perl
print "Content-type: text/html\n\n";
my...   #edited
my...   #edited
my...   #edited

print<<'EOF';
<html>
EOF
...
print "$username\n";
...
print <<'EOF';
</html>
EOF
exit(0)

i mean maybe i miss some script or something? like use .pm file




Posted by admin (Graham Ellis), 16 July 2007
You need to pick up the parameter from the form on the the third page in the same way that you pick it up on the main page.   It doesn't automatically appear in a $username variable.

Posted by KevinAD (KevinAD), 18 July 2007
muroo_08,

have you figure out how to do what you want to do?


Quote:
i mean maybe i miss some script or something? like use .pm file


You should be using the CGI.pm module to get the form data into your scripts. The method you are usng for parsing the form data will work but is generally considered bad practice.

Posted by muroo_08 (muroo_08), 19 July 2007
yea, you are right KevinAD, i have tried and that's work well, event i need some references, but thank you vary much for all your help Graham and you Kevin

Posted by KevinAD (KevinAD), 19 July 2007
very good, you're welcome.  



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho