View Full Version : Posting Data to a CGI Script
jusjay
October 23rd, 2001, 12:49 PM
I have a login script called login.cgi. Currently I use a HTML form to login. I created a Flash form to use as the login in but when I click on the submit button nothing happens.
here is the code
on (release) {
loadVariables ("http://www.jaycook.net/cgi/members/login.cgi", _root, "POST");
gotoAndStop (2);
}
does the script need to be written for Flash? The HTML form uses "post" to send the variables.
suprabeener
October 23rd, 2001, 07:52 PM
what's supposed to happen?
jusjay
October 23rd, 2001, 09:15 PM
once a user enters the user name and password the script will verify the user name then display a HTMl page after login in.
suprabeener
October 23rd, 2001, 09:34 PM
use getURL instead and _blank as a target, that will make the results come back in a new window.
jusjay
October 25th, 2001, 10:27 AM
I tried setting the taget to _blank and using the GET but nothing happened.
here is the action:
on (release) {
loadVariables ("http://www.jaycook.net/cgi/members/login.cgi", _blank, "GET");
}
The original html form uses the POST method. I tried using POSt and the traget _blank but I got the same result.
here is the url to the form.
http://www.jaycook.net/flag.html
I really do appreciate your help!
suprabeener
October 25th, 2001, 11:14 AM
try putting _blank in quotes. POST should work fine, it's safer than GET.
jusjay
October 25th, 2001, 02:09 PM
I still can't get it to work. Will you look at the .fla file? If so you can download it from
http://www.jaycook.net/form.fla
the html page is http://www.jaycook.net/form.html
I must be missing something obvious. I looked in the Flash 5 Bible and it appears that I am writing the action correctly.
suprabeener
October 25th, 2001, 02:49 PM
use getURL, like so:
on(release){
getURL("http://www.jaycook.net/cgi/members/login.cgi", "_blank", "POST");
}
now it works!!
jusjay
October 25th, 2001, 03:12 PM
that script does bring up the for built into the script but I was trying to use the flash form to login.
I guess it won't work.
thanks for you help
suprabeener
October 25th, 2001, 03:30 PM
ok, i had a closer look at the page that the cgi produces.
the script is looking for a variable "action". when you call it from flash without setting it, the cgi sees that the variable is null, and gives you the login prompt instead of processing the info.
you'll have to set the "action" variable to "login".
you can set that anywhere, but perhaps easiest on the submit button:
on (release) {
action="login";
getURL("http://www.jaycook.net/cgi/members/login.cgi", "_blank", "POST");
}
cheers.
jusjay
October 25th, 2001, 04:11 PM
I think I am a lot closer now. Here is what's going on. Once you click on the "LOGIN" button, the script reuturns 2 errors.
1 Invalid character in username.
2 No such username / password combination
The variables are not being posted. The script thinks the variables are blank. I read inside the cgi file and "whitespace" will create the "invalid character" error. I can re-create this same error on my original form by not enter a username / password. Form some reason the loadVariables.
here is the original form
http://www.jaycook.net
the flash form
http://www.jaycook.net/form.html
I know this has taken your tim and I sure you are a busy person but I really do appreciate your help.
Sincerely, Jay
suprabeener
October 25th, 2001, 04:42 PM
you could try urlencoding the data before sending it. that's
my_pass = escape(my_passwd);
my_user = escape(my_user);
otherwise i'd have to have a look at the cgi.
cheers.
jusjay
October 26th, 2001, 08:59 AM
doesn't there need to be an action to load the varialbles? How does it post them otherwise? I tried the urlencoding like this.
on(release){
action="login";
my_pass = escape(my_pass);
my_user = escape(my_user);
        getURL("<a href="http://www.jaycook.net/cgi/members/login.cgi",">www.jaycook.net/cgi/members/login.cgi",</a> "_self", "POST");
}
this produced the same result.
suprabeener
October 26th, 2001, 01:26 PM
whatever variables exist in the movie that the action is initiated form are passed. if you want to be sure that variables are being passed, call this script (this is perl), it will simply print everything that it receives:
#!/usr/bin/perl
use CGI qw(:standard);
&get_data;
print "Content-type: text/html\n\n";
foreach $key (sort keys %ENV) {
_ _ _ _ print "$key = $ENV{$key}\n";
}
foreach $key (sort keys %fields) {
_ _ _ _ print "$key = $fields{$key}\n";
}
exit;
############
sub get_data
{
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
$$key=$content;
}
}
it's a great troubleshooting script
jusjay
October 26th, 2001, 01:45 PM
I pasted the script into a file called "test.pl".
I set the action on the submit button as follows.
on(release){
getURL("<a href="http://www.jaycook.net/cgi/members/test.pl",">www.jaycook.net/cgi/members/test.pl",</a> "", "POST");
}
does the test.pl file need to be CHMOD?
thanks,
jay
suprabeener
October 26th, 2001, 01:46 PM
did a little experimenting ... here's a few things.
uncheck html on your text options, it's sending the html code as well.
you'll want to be sure to unencode the keys if you want to use underscores. with the script i posted above, the underscores are not being translated back to underscores, they remain "%5F". this is without escaping the variables first. seems to do it automatically when it POSTS.
see the line that unencodes the $content? just do the same for $key like so:
$key=~s/%(..)/pack("c",hex($1))/ge;
i think that should clear up the problems. you might consider dumping the underscores altogether.
cheers.
jusjay
October 26th, 2001, 02:13 PM
i got it to work!!
I got rid of the underscore and changed the html setting on the text input fields.
Thanks a LOT! I wouldn't have ever got that to work without your help!
Have a good weekend.
~jay~
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.