Gossamer Forum
Home : General : Perl Programming :

makign my own meta-search

Quote Reply
makign my own meta-search
Hello all,

I'm making my own meta-search, this because i have 3 databases, nut therefore i need the
in->param('type') only to be one of the following value's

web,email,stb

but the following wont work:

use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $in = new CGI;
my $query = $in->param('query');
my $query_q = &urlencode($query);
my $nh = $in->param('nh') | | 1;

$query or &homepage();

my $database = web;
if ($in->param('type') && (($in->param('type') == web) | | ($in->param('type') == email) | |
($in->param('type') == stb) | | ($in->param('type') = av))) {
$database = $in->param('type');
}


Can some help me out ?

Quote Reply
Re: makign my own meta-search In reply to
Please,

I need this feature for security....
Quote Reply
Re: makign my own meta-search In reply to
What doesn't work?

Code:
my $database = web;

Well, that looks like it might cause problems? Probably need to enclose web in quotes.

Cheers,

Alex
Quote Reply
Re: makign my own meta-search In reply to
my $database = web;
if ($in->param('type') && (($in->param('type') == web) | | ($in->param('type') ==
email) | |
($in->param('type') == stb) | | ($in->param('type') = av))) {
$database = $in->param('type');
}

---> It this piece, and i already tried it with "" , but it gives an error (maybe use strict)
Quote Reply
Re: makign my own meta-search In reply to
First off, how are you passing this information to the CGI? Is it through a hidden variable in the form or through the query string? I recently had a similar problem in which I found a solution by setting up two CGI objects:

<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>use CGI;

my $form_data = new CGI;
my $query = new CGI($ENV{'QUERY_STRING'});
</pre><HR></BLOCKQUOTE>

The reason I had to do this was because new CGI by itself was not parsing data from the query string, which was:

cart.pl?type=sf&func=add&db=store

I still have not determined if CGI.pm requires separate objects based on the forma and query data, but this may also be an aspect of using string on the program. Another mysterious bug you have is:

my $database = web;

If you are using strict, this won't work, you need to either define web as a variable ($web) or enclose it in quotes "web". Otherwise Perl simply won't know the context of the statement. In fact, I doubt this would compile even without strict.

Here is what I would suggest for the full code, you might have to tweak it for your own use:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $in = new CGI($ENV{'QUERY_STRING'};
my $form = new CGI;
my $query = $in->param('query');
my $query_q = &urlencode($query); # This may not be needed. This statement confused me
my $nh = $in->param('nh') &#0124; &#0124; 1;
my $type = $in->param('type') # This is a better coding practice and will prevent typos below.

$query or &homepage();

if ($type && (($type eq "web") &#0124; &#0124; ($type eq "email") &#0124; &#0124; ($type eq "stb") &#0124; &#0124; ($type eq "av"))) {
my $database = $type;
} else {
my $database = "web";
</pre><HR></BLOCKQUOTE>
I personally do not like layered logic like this, it has a tendancy to really wreak havoc on you if there is a bug, but sometimes that is what it takes. You could omit $type eq "web", since we set to web as a default anyway. Notice also how your equality operator was not correct, when matching a string we always use "eq" to the string value in quotes.

Hope this helps.


------------------
Fred Hirsch
Web Consultant & Programmer


[This message has been edited by fhirsch (edited January 14, 1999).]
Quote Reply
Re: makign my own meta-search In reply to
Fred,

i have to adjust the code a little, but now it works, this is my code:



#use lib '/opt/guide/www.lanx.nl/CGI_pm-2_42/';
use CGI;
use CGI::Carp qw(fatalsToBrowser);


my $in = new CGI;


# We are searching, so get the query, escape it, and use the pre-defined search-engine.
my $query = $in->param('query');
my $query_q = &urlencode($query);
my $engine = $in->param('type');
my $nh = $in->param('page') &#0124; &#0124; 1;

$query or &homepage();

# Check the kind of database we have to search, otherwise use the default.
if ($engine && (($engine eq "web") &#0124; &#0124; ($engine eq "email") &#0124; &#0124; ($engine eq "stb") &#0124; &#0124; ($engine eq "av"))) {
$database = $engine;
} else {
$database = "web";
}


print "Location: /cgi-bin/zoeken/zoeken-$database.cgi?query=$query_q&nh=$nh\n\n";
exit;

# (debug only)
#print CGI->header('text/plain');
#print "/cgi-bin/zoeken/zoeken-$database.cgi?query=$query_q&nh=$nh\n\n";
#exit;
Quote Reply
Re: makign my own meta-search In reply to
Fred:

Quote:
I recently had a similar problem in which I found a solution by setting up two CGI objects

Shouldn't have to do this! Are you trying to submit information using GET and POST at the same time? I wouldn't try that as I've found it doesn't work in all browsers! It's one or the other. Here's an example of submitting via GET and POST methods at the same time:

<form action="/script.cgi?a=b&c=d&e=f">
<input name=g value=h>
<input type=submit>
</form>

That sort of mixing of methods will cause problems.

Chrishintz:

Quote:
print "Location: /cgi-bin/zoeken/zoeken-$database.cgi?query=$query_q&nh=$nh\n\n";

Since you are using CGI.pm, I'd use:

print $in->redirect("http://www.server.com/cgi-bin/zoeken/zoeken-$database.cgi?query=$query_q&nh=$nh");

Also, you do need the full url with http://, some browsers won't redirect properly with just a partial URL.

Hope that helps!

Alex
Quote Reply
Re: makign my own meta-search In reply to
  
Quote:
print "Location: /cgi-bin/zoeken/zoeken-$database.cgi?query=$query_q&nh=$nh\n\n";

Since you are using CGI.pm, I'd use:

print
$in->redirect("http://www.server.com/cgi-bin/zoeken/zoeken-$database.cgi?query=$query_q&nh=$nh");

Also, you do need the full url with http://, some browsers won't redirect properly with just a partial URL.

I specially want that te user won't see he's being redirected to anther script, or is this not the best way to do that?

So user sees: search.cgi?query=test
but the script is: search4546.cgi?99=test&home=yyttebbd

AND in->redirect is not working, i get 500 server errors,



[This message has been edited by chrishintz (edited January 14, 1999).]