Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

method post to multiple cgi

Status
Not open for further replies.

yuhost

Programmer
Jan 23, 2006
6
0
0
NL
Hi,
Is it possible to post results from a search box to multiple cgi..

<TABLE><FORM METHOD="POST" action=" name="search"><TR><TD><input type="text" name="keywords" size=38></TD><TD width=2></TD><TD><input type=submit value=Search>
</TD></TR></FORM></TABLE><BR>

and simultaneously to...

'
etc...
 
You could do that by forwarding the request on to the second cgi file once the first has completed processing.

- George
 
Thank you for your quick response, what would be the best way of doing that please...
 
You could redirect using the URL

print redirect('
If you're using the CGI module, at the end of your first script. You'll need to be sure no errors occur on the first script or it won't get to the second. Threading might be an option for that, never tried it though

--Paul

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thank you for your response, but I am now confused, which is actually not that difficult, how would that intergrate into this script then...

<TABLE><FORM METHOD="POST" action=" name="search"><TR><TD><input type="text" name="keywords" size=38></TD><TD width=2></TD><TD><input type=submit value=Search>
</TD></TR></FORM></TABLE><BR>
 
what you posted is not a script, it's html code. The script is xxxx.cgi. You could maybe integrate both scripts into one script, that way the data gets sent to the one script and you do whatever it is you are trying to do. Otherwise try using the suggestion by Paul in your xxxx.cgi script.
 
Thank you for your responses, but I just can not get it to work, it has to post the results to a duplicate copy of the script, located in another directory..
This is the script I think it need to be posted into, as this is the xxxx.cgi, that is mentioned above...

#!/usr/bin/perl


if ($ENV{'SERVER_SOFTWARE'} =~ /microsoft/i)
{
$path = $ENV{'PATH_TRANSLATED'};
$path =~ /^(.*)\\[^\\]*$/;
$path = $1;
chdir $path;
}

require 'include/functions.cgi';
require 'include/search.cgi';
&loadsettings;

undef @cookies;

if ($settings{'debug'}) { open(DEBUG, ">$data_dir/debug.dat") }

use CGI;
use CGI::Carp qw/fatalsToBrowser/;

$smartsearch = 1;

$cgi = new CGI;
$keywords = $cgi->param('keywords');
$start = ($cgi->param('s') ne '') ? $cgi->param('s') : 0;
$username = $cgi->param('username');
$crawlsite = $cgi->param('crawlsite');
if ($crawlsite) { $settings{'crawl'} = $crawlsite }

$biddedtotal = $cgi->param('bt');
$freetotal = $cgi->param('f');
$catchall = $cgi->param('c');
$dbtotal = $cgi->param('db');
$external = $cgi->param('e');

$keywords =~ s/\///g;
$keywords =~ tr/A-Z/a-z/;
$keywords =~ s/\"//g;
$temp = '';

# Only one space between keywords
foreach ( split(/\s/, $keywords) )
{
if ( $_ ne '' )
{
if ($temp ne '') { $temp .= ' ' }
$temp .= $_;
}
}
$keywords = $temp;

if ($keywords eq '')
{
$info{'HIDDENFORM'} = '<input type="hidden" name="username" value="'.$username.'">';
&dotemplate('search_index.tpl');
exit;
}

$info{'KEYWORDS'} = $keywords;

if ($settings{'filter'})
{
if ( &dofilter($keywords) )
{
$info{'AFFILIATE'} = $username;
&dotemplate('search_filter.tpl');
exit;
}
}


if ($settings{'affiliate'} && $username ne '' && $start == 0 && $settings{'affiliate_per_search'} > 0) { require 'include/affiliate.cgi'; &afflog($username, 1, $settings{'affiliate_per_search'}) }

$klink = $keywords;
$klink =~ tr/ /+/;
$klinkgo = &Encrypt($keywords,$encryptkey,'dffkjhhrwhrh');
$klinkgo =~ s/ /+/g;

if ($settings{'dirs'}) { &dirs }

if ($start == 0 && $biddedtotal == 0)
{
$biddedtotal = -1;
$dbtotal = -1 if ($settings{'db_file'} ne '');
$freetotal = -1 if ($settings{'free_listings'});
$external = -2 if ($settings{'crawl'} ne '' || $settings{'outside_urls'} ne '');
}

$linecount = &dosearch($start, $settings{'display_max'}, 0, 'search_results_paid.tpl', 'search_results_free.tpl');

if ($linecount == 0)
{
$info{'AFFILIATE'} = $username;
&dotemplate('search_nomatch.tpl');
exit;
}

if ($dbtotal == -1) { &getdb(100000, 0, $settings{'db_file'}, $settings{'db_delimiter'}, $settings{'db_title'}-1, $settings{'db_desc'}-1, $settings{'db_url'}-1) }
if ($freetotal == -1) { &getfree(100000, 0) }
if ($external == -2)
{
require 'include/crawl.cgi';
&crawl(0, $linecount+1);
}
if ($external == -1)
{
$info{'ATLEAST'} = $settings{'search_at_least'};
$total = $biddedtotal + $dbtotal + $freetotal;
}
else { $total = $biddedtotal + $dbtotal + $freetotal + $external }

if ($linecount < $settings{'display_max'}) { $total = $start+$linecount }

if ($settings{'debug'})
{
print DEBUG "biddedtotal - $biddedtotal\n";
print DEBUG "dbtotal - $dbtotal\n";
print DEBUG "freetotal - $freetotal\n";
print DEBUG "external - $external\n";
}

$info{'TOTAL'} = $total;

if($start > 0)
{
$s = $start - $settings{'display_max'};
if ($catchall > 0) { $c = $s }
$info{'LINKPREV'} = "<a href=\"voobie.cgi?keywords=$klink&s=$s&bt=$biddedtotal&crawlsite=$crawlsite&c=$c&db=$dbtotal&e=$external&f=$freetotal&username=$username$crawlline\">$settings{display_last}</a>";
}
elsif ($settings{'logkeys'}) { &logkey }

if ($start+$linecount < $total)
{
$s = $start + $settings{'display_max'};
$info{'LINKNEXT'} = "<a href=\"voobie.cgi?keywords=$klink&s=$s&bt=$biddedtotal&crawlsite=$crawlsite&c=$catchall&db=$dbtotal&e=$external&f=$freetotal&username=$username$crawlline\">$settings{display_next}</a>";
}
$info{'START'} = $start+1;
$info{'END'} = $start+$linecount;
$info{'RESULTS'} = $results;
$info{'AFFILIATE'} = $username;

&dotemplate('search_main.tpl');

exit;


sub dotemplate
{
my ($temp) = @_;

&readtemplate('search_header.tpl');
$info{'HEADER'} = $tpl;
&readtemplate('search_footer.tpl');
$info{'FOOTER'} = $tpl;

&readtemplate($temp);
$info{'SITETITLE'} = $settings{'sitetitle'};;
$tpl =~ s/<<([^>]+)>>/$info{$1}/g;

if ($username ne '')
{
push @cookies, $cgi->cookie( -name => 'referrer', -value => $username, -expires => '+1y' );
}

print $cgi->header(-cookie=>[@cookies]);
print $tpl;
}

sub dirs
{
open(DATA, "$data_dir/directories.txt");
flock(DATA, $LOCK_SH);
$foundd = 0;
$count = 0;
my (@subcats, $subcat);
my($mycat) = '';

while ( $line = <DATA> )
{
my ($precat) = '';

$rkeywords = &regescape($keywords);
if ($line =~ /$rkeywords/i )
{
my($addto) = 1;

foreach $link ( split('/', $line) )
{
if ($link =~ /^($rkeywords)$/i)
{
$foundd = 1;
$mycat = $precat . "<b>$1</b>";
$addto = 2;
}
elsif ($addto == 1)
{
if ($link ne '')
{
$link2 = $link;
$link2 =~ tr/ /+/;
$precat .= "<a href=\"$settings{cgi_url}/voobie.cgi?keywords=$link2\">$link</a> &gt; ";
}
}
elsif ($addto == 2)
{
$subcats{$link} = $count++;
$addto = 0;
}
}
}
}
flock(DATA, $LOCK_UN);
close(DATA);

if ($foundd)
{
foreach $link ( sort { $subcats{$a} <=> $subcats{$b} } keys %subcats )
{
$link2 = $link;
$link2 =~ tr/ /+/;
$mysubcat .= "<a href=\"$settings{cgi_url}/voobie.cgi?keywords=$link2\">$link</a><br>\n";
}

$info{'CATEGORIES'} = $mycat;
$info{'SUBCATEGORIES'} = $mysubcat;
}
}


sub direct_hit
{
if ($crawlsite == 3 || $crawlsite == 5) {return;}

@kdata = split(/&&/, $keydata[0]);
if ($settings{'debug'})
{
print DEBUG "In direct_hit\n";
for $i (0..$#kdata) { print DEBUG "$i - $kdata[$i]\n" }
}

if ($kdata[0] > 0 && $kdata[5] eq '')
{
$time = &Encrypt(time(),$encryptkey,'dffkjhhrwhrh');
$user = &Encrypt($kdata[1],$encryptkey,'dffkjhhrwhrh');
$url = &Encrypt($kdata[3],$encryptkey,'dffkjhhrwhrh');
$bid = &Encrypt($kdata[0],$encryptkey,'dffkjhhrwhrh');
my $k = &Encrypt($keywords,$encryptkey,'dffkjhhrwhrh');

$direct_hit_url = "$settings{frame_url}$settings{cgi_url}/go.cgi?u=$user&url=$url&b=$bid&t=$time&k=$k";
}
elsif ($kdata[5] ne '') { $direct_hit_url = $kdata[5] }
else
{
$direct_hit_url = $kdata[3];
$direct_hit_url =~ s/\&amp;/\&/g;
}

if ($settings{'logkeys'}) { &logkey }

print "Location: $direct_hit_url\n\n";

exit;
}

sub logkey
{
open(DATA,">> $data_dir/keywordlog_$months[$month]-$dayofmonth-$year.txt");
flock(DATA, $LOCK_EX);
print DATA "$keywords\n";
flock(DATA, $LOCK_UN);
close(DATA);
}
 
I think I'm a bit confused here. You have a script (listed above) that needs to be fired off twice, once in two separate directories, to be completed? I'm guessing the reason is due to these lines:

Code:
if ($ENV{'SERVER_SOFTWARE'} =~ /microsoft/i)
{
    $path = $ENV{'PATH_TRANSLATED'};
    $path =~ /^(.*)\\[^\\]*$/;
    $path = $1;
    chdir $path;
}

But, I don't see the value in doing all of this rendering twice. What is it you are needing to accomplish that has you storing the script in two directories and such?

Could you give us a little background as to what you're looking to have done? I'm sure there's an easier solution than running the same script twice.

- George
 
It is a search script, but I want to recreate the same principal as google, the script allows for feeds from other searches to populate, but I want the paid results for the site to be listed in an area on the right hand side, instead of mixed in with the rest...
 
Thank you again for your responses, but now I am completly lost, I need the results from this..

<TABLE><FORM METHOD="POST" action=" name="search"><TR><TD><input type="text" name="keywords" size=38></TD><TD width=2></TD><TD><input type=submit value=Search>
</TD></TR></FORM></TABLE><BR>


Posted into two seperate copies of the script, thus allow me to dictate what resluts are seen where on the page, ie the first script controls free listings and feeds from other search engines, the second script controls the paid listings for the site..

The problem is, the script mixes all the results together, but I need to seperate the paid out, as per google's sponsored listings...

The script shown in a previous pos, is the 'xxx.cgi' mentioned above...

Your help would be appreciated...
 
You need to combine your two scripts into one. Here's what each of your search scripts is currently doing:

Get some parameters
Search the database with those parameters, get some results
Output those results

Here's what the new one will do:

Get some parameters
Search one database with those parameters, get result set 1
Search the other database with those parameters, get result set 2
Output both sets of results

Whilst you probably could work something out that calls the individual scripts seperately somehow, it's gonna be way more complicated that way.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Or, as usual, TMTWTDI ;-)

you could write a piece of CGI that accepts the initial request. That first piece of CGI (say 'handler.cgi') handles the request and use LWP::Simple to fire off requests to the two separate CGIs doing your search.

handler.cgi might do this....
#!/usr/bin/perl
use strict;
use CGI;
use LWP::Simple;

my $cgi_object = new CGI;

# get inputs from form submission
my $var1 = $cgi_object->param('var1');
my $var2 = $cgi_object->param('var2');

# construct a URL to the first piece of search CGI
my $url = "....?var1=$var1&var2=$var2"; # or something like that

my $first_response = get($url);
# do something with the results from the first query

# construct a URL to the second piece of search CGI
$url = .... ;

my $second_response = get($url);
# do something with the results from the 2nd query

print $cgi_object->header, $cgi_object->start_html;
print "Some treatment of what you got back from the LWP get
calls<br />\n";
print $cgi_object->end_html;

just another idea....

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top