By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

Retrieving values from the URL

mehj123
P: 55
Hi...
I have written some cgi scripts and I need to pass the user id and password between them.. There is a Login page which passes the user name and password to another cgi script through the url which in turn encrypts it and passes it to the next cgi script (again through url). The third cgi script is also able to retrieve the values (using the param method), it adds another variable to the url and passes to the next cgi script..

The strange thing is that in this last cgi, the url has all the values namely the user id, password and the third variable, but I can retrieve only the third variable in the cgi script.. Whatever I do, I cant get the user id and password. I tried printing the url using the query_string, but it also prints something like this
r=42.2, while I can see that the actual url is
Expand|Select|Wrap|Line Numbers
  1. http://xyz/fourth.cgi?r=42.2&f1=abc&f2=xxx
where f1, f2 are user name and password respectively..

I am posting here only the third and fourt cgi..

Third.cgi
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use CGI qw/:standard/;
  4. print  "Content-type:text/html\n\n";
  5. my $g_userid = param('field1');
  6. my $g_pwd = param('field2');
  7. print $g_userid; # its printing the values correctly
  8. print $g_pwd;
  9.  
  10. print  "
  11. <HTML>
  12.        <HEAD>
  13.         <script language='javascript'>
  14.         function submit_form()
  15.         {
  16.             var r = \"42.2\";
  17.             var user = \"$g_userid\";
  18.             var pwd = \"$g_pwd\";
  19.             alert(user);
  20.             alert(pwd);                                document.myform.action=document.myform.action+'?r='+r+'&f1='+user+'&f2='+pwd;
  21.                       var action = document.myform.action;
  22.                       alert(action);
  23.                    document.myform.submit();           
  24.         }
  25.     </script>
  26.     </HEAD>
  27.     <BODY>
  28.     <FORM ACTION=\"../xyz/fourth.cgi\" name=\"myform\" id=\"MyForm\" method=\"post\">
  29.   print "<input type='button' onclick='javascript:submit_form()' value='Click here\s'>
  30.     </FORM>
  31.     </BODY>
  32. </HTML>";
  33. exit(0);
Fourth.cgi

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use CGI qw/:standard/;
  4. print  "Content-type:text/html\n\n";
  5. my $g_r=param('r');
  6. my $g_usid = param('f1');
  7. my $g_pd = param('f2');
  8.  
  9. print $g_r; # this gets printed
  10. print $g_usid; # no value for this
  11. print $g_pd;#no value for this
  12. my $string = query_string;
  13. print $string; # only the string r=42.2 gets printed
  14.  
Is there anything wrong? Why am I able to retrieve only one value from the url? Please help...(Sorry for the long post but I am stuck with this for 2 days :( )

Thanks
Mehj
Mar 12 '08 #1
Share this Question
Share on Google+
4 Replies


KevinADC
Expert 2.5K+
P: 4,059
It looks like you are mixing GET (in the javascript) and POST data in Third.cgi. Normally that is not something you want to do. Pick which method you want to use, GET or POST and stick with it.
Mar 12 '08 #2

mehj123
P: 55
It looks like you are mixing GET (in the javascript) and POST data in Third.cgi. Normally that is not something you want to do. Pick which method you want to use, GET or POST and stick with it.
Thanks for the reply KevinADC.. I modified my scripts so that all the method are "Get". But still no change in what output I get. The strange fact is that I am able to get the third variable and ,as I said above also, the entire url is correct.. I dont know why it is not getting the values into the script..
Mar 12 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
This is the way I would do it if I were going to use javasacript:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use CGI qw/:standard/;
  4. print  "Content-type:text/html\n\n";
  5. my $g_userid = 'userid';
  6. my $g_pwd = 'userpassword';
  7. print $g_userid; # its printing the values correctly
  8. print $g_pwd;
  9.  
  10. print  qq{
  11. <HTML>
  12.        <HEAD>
  13.         <script language='javascript'>
  14.         function submit_form()
  15.         {
  16.             var r = "42.2";
  17.             var user = "$g_userid";
  18.             var pwd = "$g_pwd";
  19.             document.myform.id.value = user;
  20.             document.myform.pwd.value = pwd;
  21.             document.myform.r.value = r;
  22.             document.myform.submit();           
  23.         }
  24.     </script>
  25.     </HEAD>
  26.     <BODY>
  27.     <FORM ACTION="fourth.cgi" name="myform" id="MyForm" method="post">
  28.     <input type=hidden name=id value=''>
  29.     <input type=hidden name=pwd value=''>
  30.     <input type=hidden name=r value=''>
  31.     <input type='button' onclick='javascript:submit_form()' value='Click here'>
  32.     </FORM>
  33.     </BODY>
  34. </HTML>};
  35. exit(0);
  36.  
Mar 12 '08 #4

mehj123
P: 55
This is the way I would do it if I were going to use javasacript:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use CGI qw/:standard/;
  4. print  "Content-type:text/html\n\n";
  5. my $g_userid = 'userid';
  6. my $g_pwd = 'userpassword';
  7. print $g_userid; # its printing the values correctly
  8. print $g_pwd;
  9.  
  10. print  qq{
  11. <HTML>
  12.        <HEAD>
  13.         <script language='javascript'>
  14.         function submit_form()
  15.         {
  16.             var r = "42.2";
  17.             var user = "$g_userid";
  18.             var pwd = "$g_pwd";
  19.             document.myform.id.value = user;
  20.             document.myform.pwd.value = pwd;
  21.             document.myform.r.value = r;
  22.             document.myform.submit();           
  23.         }
  24.     </script>
  25.     </HEAD>
  26.     <BODY>
  27.     <FORM ACTION="fourth.cgi" name="myform" id="MyForm" method="post">
  28.     <input type=hidden name=id value=''>
  29.     <input type=hidden name=pwd value=''>
  30.     <input type=hidden name=r value=''>
  31.     <input type='button' onclick='javascript:submit_form()' value='Click here'>
  32.     </FORM>
  33.     </BODY>
  34. </HTML>};
  35. exit(0);
  36.  
Thank you so much for taking out the time in helping me.. It is working.. thanks again...:)
Mar 12 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.