Solved

Check my database? How to?

Posted on 1998-11-20
11
208 Views
Last Modified: 2013-12-25
I need to do this:

I have a database where I enter my data.

Let's say data 1 is ABCD, this code is located on a page (hidden in a button) on another server. When one click on the button that contain the code, I want the user to be sent to a specific page (on another server) ONLY if the code is in my database.

In another words the new page will open ONLY if it can find the code sent from the other page in my database. If not it will open another page.

???
0
Comment
Question by:wirefram
  • 6
  • 3
  • 2
11 Comments
 
LVL 1

Expert Comment

by:flivauda
ID: 1829690
have your scrip that is receiving the submit output different locations if they code is there or not :


#!/usr/bin/perl

&parse_form_data(*FORM);
if ($FORM{'databasecode'} is in my database)
{
  print  "Location:http://www.myhomepage.com/thiswasthere.html\n\n";
}
else
{
  print  "Location:http://www.myhomepage.com/thiswasnotthere.html\n\n";
}


sub parse_form_data
{
    local (*FORM_DATA) = @_;
    local ( $query_string, @key_value_pairs,
                          $key_value, $key, $value);

    read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});

    @key_value_pairs = split (/&/, $query_string);
    foreach $key_value (@key_value_pairs) {
        ($key, $value) = split (/=/, $key_value);
        $value =~ tr/+/ /;
        $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;

        if (defined($FORM_DATA{$key})) {
            $FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value);
        } else { $FORM_DATA{$key} = $value;
        }
    }
}

0
 

Author Comment

by:wirefram
ID: 1829691
I am totally new with Perl.
Your form looks good but where do I write the name of my database for the form to check?

My database is data.txt


0
 

Author Comment

by:wirefram
ID: 1829692
This is the beginning of my script, at some point I should be able to insert the function you provided but could you explain in details what I have to typed exactly?
++++++++++++++++++++++++++++++++++
$current_time = time();

$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);
foreach $item(@pairs) {
      ($key,$content)=split (/=/,$item,2);
      $content=~tr/+/ /;
      $content=~ s/%(..)/pack("c",hex($1))/ge;
      $fields{$key}=$content;
}
$r=0;
if ($fields{'ID'} == 0) {
open (DAT,"<members.db");
if ($use_flock) {
flock DAT, 2;
}
@database_array = <DAT>;
close (DAT);
&thehtml;
}
unless ($fields{'ID'}) {

print "Location: $addsite_location/welcome.html\n\n";
exit;
}

open (DAT,"<members.db");
if ($use_flock) {
flock DAT, 2;
}
@database_array = <DAT>;
close (DAT);


&member_in;
exit;
+++++++++++++++++++++++++++

If the ID is found I want to open the "welcome.html" if the ID is not found I want to open "wrongpage.html".

members.db is the database


0
 
LVL 1

Expert Comment

by:flivauda
ID: 1829693
if ($FORM{'databasecode'} is in my database)

this line is what you need to use your code for. the $FORM{'databasecode'} is just what i was reading out of the html form element databasecode.

so run your code to decide if it is in your database and set a flag when you find it:

$found = 0;
.
code checking if it is in the database
if the item is in the database { $found = 1; }

then you would have

     if ($found == 1)
     {
       print  "Location:http://www.myhomepage.com/welcome.html\n\n";
     }
     else
     {
       print  "Location:http://www.myhomepage.com/wrongpage.html\n\n";
     }
0
 

Author Comment

by:wirefram
ID: 1829694
Well, can't say I feel better, if you look at the beginning of my script, where do I type your stuff?

Do you have a real example using the same names than in my script?  
if ($FORM{'databasecode'} is in my database) //is it what I have to replace with ($fields{'ID'})  in my script? Do I really write "is in my database" or is it something like "=1"

???I told you I never did a cgi before and i am using a free script that I try to adjust to my needs!
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Expert Comment

by:flivauda
ID: 1829695
do whatever code you need to, to determine if the item is in your database if you find it set a flag.  then change the if .. is in my datase to
if ($flag == 1)
0
 

Author Comment

by:wirefram
ID: 1829696
Can you look at the beginning of my script (posted on my 3rd message) and tell me exactly where I write the flag stuff.

I assume it's in this part of the script because it contain

print "Location: $addsite_location/welcome.html\n\n";

Somewhere in this area I should have something that explain to open another page if not found.

Honestly set a  flag is above my actual understanding of perl!

Sorry, I look stupid! (and feel the same)

0
 

Author Comment

by:wirefram
ID: 1829697
Can someone look at my script (posted previously) and tell me exactly where to insert the code that check the ID?

Thanks

0
 

Accepted Solution

by:
inkumc earned 40 total points
ID: 1829698
wirefram;
In your previous script, you had the below as stated:

$r=0;
if ($fields{'ID'} == 0) {
open (DAT,"<members.db");
if ($use_flock) {
flock DAT, 2;
}
This is what you need to do...before you set the above script to open the database file to check who should enter, you need to know about how a .htaccess works...With htaccess, you can create a inset who should get access and who shouldn't...it works the same way as the one you had previously. ::open a particular page if the information provided is correct else
                               open a second.
Please let me know of what you think....

0
 

Author Comment

by:wirefram
ID: 1829699
I haven't try yet but what you say is totally logical, in the htaccess I can redirect to the page I want (I think?)

I'll try that.

Thanks
0
 

Expert Comment

by:inkumc
ID: 1829700
No problem...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now