Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

how to make user correctly answer r

Original Message
Name: CrasH
Date: November 20, 2007 at 14:09:26 Pacific
Subject: how to make user correctly answer r
OS: OS X 10.5.1
CPU/Ram: Intel Core2Duo 2GB RAM
Model/Manufacturer: MacBook Pro
Comment:
Perhaps a scenario will best explain what I'm looking to do. My google searches have not led me to an answer yet:

I've written a book. Along with the book comes a file to download from my website. I wish to protect the download from those who have NOT bought the book though. To do this, I'd like the equivalent of password protection but with a twist.

When you go to the page the book tells you to, you are greeted by a question and a form box to fill in your answer. The question is basically along the lines of "what is the 4th word in the first full paragraph on page 34?" If you answer the question correctly, you are in and can download the file. If not, you are kicked out. HOWEVER, I'd like the question to be a random selection from a list of pre-defined question/answer combinations. This way, someone can't figure out what the question is and tell everyone. They'd have to know upwards of 75 question and answer combos because there's no telling which one you'll get.

Anyone have any ideas? I know of random fortune scripts that display a random fortune from a list in a file, but how to work something like that so that the form entry box would know which fortune/question was being asked?

Any ideas?

Thanks in advance,

CrasH


You are not defined by who you work for, but by Whom you work for.


Report Offensive Message For Removal


Response Number 1
Name: smbotans
Date: November 20, 2007 at 19:34:48 Pacific
Subject: how to make user correctly answer r
Reply: (edit)
hey,

something like that can easily be setup in php ... it will require a combination of a text file that contains your questions and answers and a form that asks the question and processes the answers

i am not aware of any ready made scripts that does that but a couple of hours work should do the trick if you know php

if you don't know php, try www.rentacoder.com and list your project

hope this helps

serge

SEO Resource

FREE Keyword Report from Meta Keywords Advice


Report Offensive Follow Up For Removal

Response Number 2
Name: CrasH
Date: November 20, 2007 at 20:34:07 Pacific
Subject: how to make user correctly answer r
Reply: (edit)
I figured it was simple. The rentacoder.com is the most USEFUL info. so far. Thanks.

You are not defined by who you work for, but by Whom you work for.


Report Offensive Follow Up For Removal

Response Number 3
Name: Michael J (by mjdamato)
Date: November 20, 2007 at 21:30:26 Pacific
Subject: how to make user correctly answer r
Reply: (edit)
Here is a fully working script. Just put your question/answer combinations into the array - you can have as many as you want.

<?php

$questionAry = array (
'75' => "What page does chapter 4 start on?",
'8' => "How many words are in the first sentence of chapter 9?",
'blue' => "What color is the cover?"
);

$error = false;

if (isset($_POST['question']) && isset($_POST['answer'])) {

$question = $_POST['question'];
$answer = $_POST['answer'];

if (empty($answer) || empty($question)) {
$error = "All required information not entered.";

} elseif (!in_array($question, $questionAry)) {

$error = "Unable to verify question." ;

} elseif (array_search($question, $questionAry)!=$answer) {

$error = "Incorrect answer.";

} else {

header('Location: path/file.ext');
exit;
}
}

//Get a random question
shuffle($questionAry);
$question = $questionAry[0];

?>
<html>
<head></head>
<body>
<h1>Answer the question</h1>


<p style="color:red;"><?php echo $error; ?></p>


<form name="questionform" method="POST">
Question: <?php echo $question; ?>

<input type="hidden" name="question" value="<?php echo $question; ?>">
Answer: <input type="text" name="answer" value="">


<button type="submit">Submit</button>
</form>
</body>
</html>

Michael J


Report Offensive Follow Up For Removal

Response Number 4
Name: CrasH
Date: November 25, 2007 at 07:13:25 Pacific
Subject: how to make user correctly answer r
Reply: (edit)
Is there a way to modify the script to read an array from a text file? That way the script could be recycled relatively easily for other projects. Also, I've taken it on myself to learn PHP and I'm not seeing how getting this question correct would take you to another page with a download link or offer up a link for you etc.

Don't get me wrong, I'm grateful for the work you've done. Just not quite understanding all that I'm looking at.

You are not defined by who you work for, but by Whom you work for.


Report Offensive Follow Up For Removal

Response Number 5
Name: FishMonger
Date: November 25, 2007 at 12:26:26 Pacific
Subject: how to make user correctly answer r
Reply: (edit)
Reading in the Q and A from a text file (or database) is easy. I don't like using php, so I'll let Michael show you how his script would need to be modified.

If you're interested, here's how it can be done in Perl.

This assumes that the Q and A file is formatted as: question=answer

=======================================================

use strict;
use CGI qw(:standard);
use File::Slurp;

my %QandA = read_file( '/path/to/QandA' ) =~ /^([^=]+)=(.*)$/mg ;
my @questions = keys %QandA;

print header(), start_html('Answer my question');

if( param('answer') ) {
if ( param('answer') eq $QandA{param('question')} ) {
print h2('Your answer is correct, you may proceed');
}
else {
print h2('Your answer was incorrect');
}
}
else {
my $question = $questions[rand(75)];
print start_form(action=>self_url()),
h2($question), hidden('question', $question),
textfield('answer'),
submit(), end_form();
}
print end_html();

=======================================================

Note:
This forum is not programmer friendly i.e., it strips out the indentation.


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: how to make user correctly answer r

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




XP Installed to G?

exessive internet traffic

ZoneAlarm Question. Blocked Connect

Windows Live Messenger Problem

Delete $Uninstall after SP3 updates


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC