# Posting Data to a CGI Script

**URL:** https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685
**Category:** programming
**Created:** [October 23, 2001, 4:49pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685 "2001-10-23T16:49:01Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 23, 2001, 4:49pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/1 "2001-10-23T16:49:01Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 23, 2001, 11:52pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/2 "2001-10-23T23:52:12Z")

</div>

what’s supposed to happen?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 24, 2001, 1:15am UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/3 "2001-10-24T01:15:36Z")

</div>

once a user enters the user name and password the script will verify the user name then display a HTMl page after login in.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 24, 2001, 1:34am UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/4 "2001-10-24T01:34:24Z")

</div>

use getURL instead and \_blank as a target, that will make the results come back in a new window.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 25, 2001, 2:27pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/5 "2001-10-25T14:27:16Z")

</div>

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](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](http://www.jaycook.net/flag.html)

I really do appreciate your help!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 25, 2001, 3:14pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/6 "2001-10-25T15:14:22Z")

</div>

try putting \_blank in quotes. POST should work fine, it’s safer than GET.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 25, 2001, 6:09pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/7 "2001-10-25T18:09:33Z")

</div>

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](http://www.jaycook.net/form.fla)

the html page is [http://www.jaycook.net/form.html](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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 25, 2001, 6:49pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/8 "2001-10-25T18:49:05Z")

</div>

use getURL, like so:

```auto
 
on(release){
   getURL("http://www.jaycook.net/cgi/members/login.cgi", "_blank", "POST");
}

```

now it works!!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 25, 2001, 7:12pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/9 "2001-10-25T19:12:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 25, 2001, 7:30pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/10 "2001-10-25T19:30:06Z")

</div>

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:

```auto
  
on (release) {
   action="login";
   getURL("http://www.jaycook.net/cgi/members/login.cgi", "_blank", "POST");
}

```

cheers.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 25, 2001, 8:11pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/11 "2001-10-25T20:11:42Z")

</div>

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](http://www.jaycook.net)

the flash form  
[http://www.jaycook.net/form.html](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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 25, 2001, 8:42pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/12 "2001-10-25T20:42:20Z")

</div>

you could try urlencoding the data before sending it. that’s

```auto
 
my_pass = escape(my_passwd);
my_user = escape(my_user);

```

otherwise i’d have to have a look at the cgi.

cheers.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 26, 2001, 12:59pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/13 "2001-10-26T12:59:23Z")

</div>

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);  
&nbsp &nbsp &nbsp &nbsp getURL("\<a href=“[http://www.jaycook.net/cgi/members/login.cgi","](http://www.jaycook.net/cgi/members/login.cgi%22,%22)\>[www.jaycook.net/cgi/members/login.cgi](http://www.jaycook.net/cgi/members/login.cgi)”,\</a\> “\_self”, “POST”);

}

this produced the same result.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 26, 2001, 5:26pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/14 "2001-10-26T17:26:53Z")

</div>

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:

```auto
  
#!/usr/bin/perl

use CGI qw(:standard);

&get_data;

print "Content-type: text/html

";

foreach $key (sort keys %ENV) {
_ _ _ _ print "$key = $ENV{$key}
";
}

foreach $key (sort keys %fields) {
_ _ _ _ print "$key = $fields{$key}
";
}

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 26, 2001, 5:45pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/15 "2001-10-26T17:45:33Z")

</div>

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","](http://www.jaycook.net/cgi/members/test.pl%22,%22)\>[www.jaycook.net/cgi/members/test.pl](http://www.jaycook.net/cgi/members/test.pl)”,\</a\> “”, “POST”);  
}

does the test.pl file need to be CHMOD?

thanks,

jay

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 26, 2001, 5:46pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/16 "2001-10-26T17:46:42Z")

</div>

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:

```auto
 
    $key=~s/%(..)/pack("c",hex($1))/ge;

```

i think that should clear up the problems. you might consider dumping the underscores altogether.

cheers.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 26, 2001, 6:13pm UTC](https://forum.kirupa.com/t/posting-data-to-a-cgi-script/3685/17 "2001-10-26T18:13:25Z")

</div>

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~
