Reputation: 1911
I'm using my own security form or you can say security challenge question.
But the problem is that I have change that question daily manually.
Is there any way to change it automatically after every 5 minutes?
Here is code of this:
if (!$_POST['security_question'] || $_POST['security_question'] != '**PUT HERE YOUR QUESTION?**' ) {
$errors[] = t('You must answer security question correctly!');
}
<tr class="row1">
<td>'.t('Security Question:').'</td>
<td>**PUT HERE YOUR QUESTION?**
<input type="text" name="security_question"/>
</td>
</tr>
So I want to change the link "PUT HERE YOUR QUESTION?" in both case randomly after some time interval.
Upvotes: 0
Views: 3343
Reputation: 1911
I Got The answer and it's working perfectly..!! Thanks to every one
// Create a random number between 0 and 9999 every 5 minutes
function random() {
$interval = 60*5; // Interval in seconds
srand(floor(time() / $interval));
echo rand(0, 9999);
}
Upvotes: 1
Reputation: 8296
If I were you, I would not re-invent the wheel and go for a tried and tested solution such as reCaptcha.
If however, you really must come up with your own solution - as usual there are many answers that could be considered correct.
First of all - if you're using a database, you could store a whole set of security phrases in there and pick one out at random - if using MySQL:
SELECT question,answer FROM security_questions ORDER BY RAND();
Alternatively, you could simply store a bunch of questions in an array:
$myQuestions = array("What is four plus three?", "What is two plus one?");
$myAnswers = array("7","3");
$random = array_rand($myQuestions);
$rndQuestion = $myQuestions[$random];
$rndAnswer = $myAnswers[$random];
Or you could make one up on the fly if you're using maths questions:
$value1 = rand(0,10);
$value2 = rand(0,10);
$question = "What is ".$value1." plus ".$value2."?";
$answer = $value1 + $value2;
What you must be very mindful of in all of these situations is coding your page in such a way that a hacker can't get circumvent it, or grab the answer from a HTTP request thats going on in the background etc.
I would still be using reCaptcha :)
Upvotes: 0