Calling another cgi program using CGI.pm

D

dmedhora

Hi All,

I'm trying out CGI.pm and I've been able to understand how
the textfields, textareas, radio buttons, checkboxes, and submit
buttons etc work.

But can I ask, if upon clicking a submit button I want to call
another CGI perl script, how do i do that ?

So far, using the param function the CGI.pm documentation
only shows how to use conditional printing of variables.

Is there any way I can call another cgi perl file to continue
onto other web pages using CGI ?

I don't want to have to use any barebones html, just CGi functions

Thanks!
 
X

xhoster

Hi All,

I'm trying out CGI.pm and I've been able to understand how
the textfields, textareas, radio buttons, checkboxes, and submit
buttons etc work.

But can I ask, if upon clicking a submit button I want to call
another CGI perl script, how do i do that ?

It isn't exactly clear what you want, it seems like you lack a fundamental
understanding of what CGI is--when the user hits submit in a web form, it
is the browser, not the server, that does the calling. Are you aware of
the -action argument to start_form?

Xho
 
D

dmedhora

I have an index.pl script that i put in my cgi-bin
Lets say its a simple login screen, so get a username
and a password. Validate that against a mysql database
using DBI and then if the password is correct, go to another
page ( another perl script that will use CGI to gather/update/view
other information from a database ? hope this sounds right)
Thats what i want to do basically. But I don't know how to do
that on clicking the submit button.

Lets say if the index.pl program above validates the user/password
successfully then how do I continue to another html page?
say, continue.pl
:)
Thanks
 
X

xhoster

I have an index.pl script that i put in my cgi-bin
Lets say its a simple login screen, so get a username
and a password. Validate that against a mysql database
using DBI and then if the password is correct, go to another
page ( another perl script that will use CGI to gather/update/view
other information from a database ? hope this sounds right)

If you don't want a session, just a one-off check and then do something,
then why not just do the password check in the same script that does
whatever it is you want to do?
Thats what i want to do basically. But I don't know how to do
that on clicking the submit button.

Lets say if the index.pl program above validates the user/password
successfully then how do I continue to another html page?
say, continue.pl

Take the validation code out of index.pl, and put in continue.pl (or put it
in my_validate.pm and use that library from continue.pl.

Xho
 
A

alpha_beta_release

or use CGI.pm,

-----------------------------
use CGI;

my $page = new CGI;

if (validate_ok($page->param('user'), $page->param('password')) {
$page->redirect( 'http://tosomewhere.cgi?user='$page->param('user')
);
}

# else, print login form

-----------------------------

Tad said:
[ Please do not top-post! }


Lets say if the index.pl program above validates the user/password
successfully then how do I continue to another html page?
say, continue.pl


If continue.pl accepts GET requests, you can issue a "redirect":

print "Location: http://www.yoursite.com/cgi-bin/continue.pl\n\n";

or some such.



[ snip TOFU]
 
A

alpha_beta_release

or use CGI.pm,

-----------------------------
use CGI;

my $page = new CGI;

# assuming validate_ok() is the function to validate your user

if (validate_ok($page->param('user'), $page->param('password')) {
print $page->redirect(
'http://tosomewhere.cgi?user='.$page->param('user'));
}

# else, print login form

-----------------------------

Tad said:
[ Please do not top-post! }


Lets say if the index.pl program above validates the user/password
successfully then how do I continue to another html page?
say, continue.pl


If continue.pl accepts GET requests, you can issue a "redirect":

print "Location: http://www.yoursite.com/cgi-bin/continue.pl\n\n";

or some such.



[ snip TOFU]
 
D

dmedhora

Hi and Thanks for your replies,
I did what you said but I'm getting this message:-

Status: 301 Location: http://localhost/cgi-bin/index2.pl

as soon as i press the submit button.

Note I tried using the function oriented as well as the OO styles.
Here is my very basic index.pl and index2.pl
( The main page and the called page )

index.pl
======
#!/usr/bin/perl
use CGI;
$cgi=new CGI;
print $cgi->header,
$cgi->start_html,
$cgi->start_form,
"Username ",
$cgi->textfield(-name=>'username',-default=>'user1'),
"Password ",
$cgi->textfield(-name=>'password',-default=>'pass1'),
$cgi->submit(-name=>'login',-value=>'Login');
if($cgi->param("username") eq "user1")
{
#As per your suggestion
print
$cgi->redirect(-uri=>"http://localhost/cgi-bin/index2.pl",-status=>301);
}
$cgi->endform;

index2.pl
=======
#!/usr/bin/perl
use CGI qw/:all/;
print header,
start_html('My Title'),
start_form,
"To be continued...",p;
print endform;

Thanks!:)

alpha_beta_release said:
or use CGI.pm,

-----------------------------
use CGI;

my $page = new CGI;

# assuming validate_ok() is the function to validate your user

if (validate_ok($page->param('user'), $page->param('password')) {
print $page->redirect(
'http://tosomewhere.cgi?user='.$page->param('user'));
}

# else, print login form

-----------------------------

Tad said:
[ Please do not top-post! }


Lets say if the index.pl program above validates the user/password
successfully then how do I continue to another html page?
say, continue.pl


If continue.pl accepts GET requests, you can issue a "redirect":

print "Location: http://www.yoursite.com/cgi-bin/continue.pl\n\n";

or some such.



[ snip TOFU]
 
T

Tad McClellan

Hi and Thanks for your replies,


Many folks will think that your thanks are not sincere when
you ignore the content of the replies.

Tad said:
[ Please do not top-post! }


Please do not top-post!

It is seen as being rude.

If you don't want to be seen as rude, then stop doing it.

If you don't know what top-posting is, then you should find out
what it is if you don't want to be seen as rude.

Have you seen the Posting Guidelines that are posted here frequently?



[ snip yet more TOFU ]
 
X

xhoster

M

Mumia W.

[...]
Is there any way I can call another cgi perl file to continue
onto other web pages using CGI ?

Yes,

$cgi->start_form(-action => 'index2.cgi');
I don't want to have to use any barebones html, just CGi functions

Thanks!

IMO, you should have a solid knowledge of HTML before learning
CGI, because you will constantly have to debug CGI scripts
that output HTML, and if you don't know HTML, you won't be
able to tell why your scripts are failing.
 
A

anno4000

Tad McClellan said:
[ Please do not top-post! }

Lets say if the index.pl program above validates the user/password
successfully then how do I continue to another html page?
say, continue.pl

If continue.pl accepts GET requests, you can issue a "redirect":

print "Location: http://www.yoursite.com/cgi-bin/continue.pl\n\n";

But then someone could go bypass the validation page and go directly
to http://www.yoursite.com/cgi-bin/continue.pl

Right. The CGI script would have to serve the protected data itself,
from sources that are not otherwise accessible from the web. That
could be tricky.

In apache web servers there's the .htaccess mechanism that is designed
(among other things) to add password-protection to pages. That kind of
solution is certainly better than self-made security via CGI.

Anno
 
A

alpha_beta_release

i think your script flow is not quite correct.

Test the param first,
if it exist then process the param, and if valid go to the next page.
else show the form. (again if invalid)

And also do remember, use session to keep track of the logged-in user.

#!/usr/bin/perl -Tw
use CGI;

$cgi=new CGI;
if($cgi->param("username") eq "user1") {
print
$cgi->redirect(-uri=>"http://localhost/cgi-bin/index2.pl",-status=>301);
# ^ what's
status for?
exit;
}
print $cgi->header,
$cgi->start_html,
$cgi->start_form,
"Username ",
$cgi->textfield(-name=>'username',-default=>'user1'),
"Password ",
$cgi->textfield(-name=>'password',-default=>'pass1'),
$cgi->submit(-name=>'login',-value=>'Login');
$cgi->endform;

----------------------------------

Hi and Thanks for your replies,
I did what you said but I'm getting this message:-

Status: 301 Location: http://localhost/cgi-bin/index2.pl

as soon as i press the submit button.

Note I tried using the function oriented as well as the OO styles.
Here is my very basic index.pl and index2.pl
( The main page and the called page )

index.pl
======
#!/usr/bin/perl
use CGI;
$cgi=new CGI;
print $cgi->header,
$cgi->start_html,
$cgi->start_form,
"Username ",
$cgi->textfield(-name=>'username',-default=>'user1'),
"Password ",
$cgi->textfield(-name=>'password',-default=>'pass1'),
$cgi->submit(-name=>'login',-value=>'Login');
if($cgi->param("username") eq "user1")
{
#As per your suggestion
print
$cgi->redirect(-uri=>"http://localhost/cgi-bin/index2.pl",-status=>301);
}
$cgi->endform;

index2.pl
=======
#!/usr/bin/perl
use CGI qw/:all/;
print header,
start_html('My Title'),
start_form,
"To be continued...",p;
print endform;

Thanks!:)

alpha_beta_release said:
or use CGI.pm,

-----------------------------
use CGI;

my $page = new CGI;

# assuming validate_ok() is the function to validate your user

if (validate_ok($page->param('user'), $page->param('password')) {
print $page->redirect(
'http://tosomewhere.cgi?user='.$page->param('user'));
}

# else, print login form

-----------------------------

Tad said:
[ Please do not top-post! }



Lets say if the index.pl program above validates the user/password
successfully then how do I continue to another html page?
say, continue.pl


If continue.pl accepts GET requests, you can issue a "redirect":

print "Location: http://www.yoursite.com/cgi-bin/continue.pl\n\n";

or some such.



[ snip TOFU]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top