Solved

Check my database? How to?

Posted on 1998-11-20
11
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

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

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

710 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