Solved

Check my database? How to?

Posted on 1998-11-20
11
206 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:flivauda
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No problem...
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 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

6 Experts available now in Live!

Get 1:1 Help Now