Solved

Check my database? How to?

Posted on 1998-11-20
11
209 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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
 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.

770 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