security code for register

Started on the old forum in August 2009 · view the original in the archive · old links redirect here

12 replies · 1,100 views · started 17 years ago · 1 min read

5 participants
CreativityKills Lead · 833 posts #3

Search google 4 captcha snippet or use plain text like:

function regSimpleAuth(){
$num1 = rand(1,20); $num2 = rand(1,20);
$ans = $num1 + $num2;
return array('question'=>'$num1 + $num2','answer'=>'$ans');
}

//reg page
$auth = regSimpleAuth();
$_SESSION['ans'] = $auth['answer'];
echo 'Are u human?<br/>'.$auth['question'].' = ';
echo '<input type="text" name="authSum" value="?" size="3" maxlength="3"/><br/>';

//use this in validation
if($_POST['authSum']!= $_SESSION['ans']){
echo 'Incorrect validation answer. E.g 8+8=16';
}else{
//continue registration
}

hope that helps.

kiLLeR-eyEd_14 Senior · 382 posts #4

mobileGIGS wrote: Search google 4 captcha snippet or use plain text like:

function regSimpleAuth(){
$num1 = rand(1,20); $num2 = rand(1,20);
$ans = $num1 + $num2;
return array('question'=>'$num1 + $num2','answer'=>'$ans');
}

//reg page
$auth = regSimpleAuth();
$_SESSION['ans'] = $auth['answer'];
echo 'Are u human?<br/>'.$auth['question'].' = ';
echo '<input type="text" name="authSum" value="?" size="3" maxlength="3"/><br/>';

//use this in validation
if($_POST['authSum']!= $_SESSION['ans']){
echo 'Incorrect validation answer. E.g 8+8=16';
}else{
//continue registration
}

hope that helps.

tnx 4 diz..

CreativityKills Lead · 833 posts #7

Or u myt prefer a captcha image script

<?php
$font = 'arial.ttf';
$lineCount = 10;
$fontSize = 10;
$height = 25;
$width = 80;
$ih = imagecreate($width,$height) or die('GD Library must be installed.');
$bgColor = imagecolorallocate($ih,0,0,0);
$lineColor = imagecolorallocate($ih,178,238,238);
$txtColor = imagecolorallocate($ih,255,255,255);
$str = 'abcdefghijklmnopqrstuvwxyz0123456789';
for($x=0;$x<6;$x++){
$pos = rand(0,strlen($str));
$stri .= $str{$pos};
}
$textbox = imagettfbox($fontSize,0,$font,$stri) or die('Try replacing imagettfbox with imagettfbbox function on d left.');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($ih,$fontSize,0,$x,$y,$txtColor,$font,$stri);
for($x=0;$x<$lineCount;$x++){
$x1 = rand(0,$width); $x2= rand(0,$width); $y1 = rand(0,$width); $y2 = rand(0,$width);
imageline($ih,$x1,$y1,$x2,$y2,$lineColor);
}
header('Content-type: image/jpeg');
imagejpeg($ih,NULL,75);
imagedestroy($ih);
session_start();
$_SESSION['captchaAuth'] = $stri;
?>

Store that code above as captchaimage.php

//the form
echo '<img src="captchaimage.php" alt="captcha"/><br/>Enter text above:<input type="text" maxlength="6" name="auth"/>';

//the authentication
session_start();
if($_POST['auth']!=$_SESSION['captchaAuth']){ echo 'Incorrect code, try again. Note: cAsE SenSITivE VaLUE';
}else{
//continue reg
}

Remember, download arial.ttf FONT, and save it in d same directory as ur php code. You can get one in ur windows folder on any pc. C:\WINDOWS\FONT(or fonts)

bijaybd Developer · 178 posts #8

i cant make it work can sombody help me :::

//reg page $auth = regSimpleAuth(); $_SESSION['ans'] = $auth['answer']; echo 'Are u human? '.$auth['question'].' = ';

it shows error like : Are u human? $num1 + $num2 =

the numbers does not show echo '<input type="text" name="authSum" value="?" size="3" maxlength="3"/> ';

kiLLeR-eyEd_14 Senior · 382 posts #10

bijaybd wrote: i cant make it work can sombody help me :::

//reg page $auth = regSimpleAuth(); $_SESSION['ans'] = $auth['answer']; echo 'Are u human? '.$auth['question'].' = ';

it shows error like : Are u human? $num1 + $num2 =

the numbers does not show echo '<input type="text" name="authSum" value="?" size="3" maxlength="3"/> ';

try, $question = "$num1 + $num2"; then in array('question'=>'".$question."');

bijaybd Developer · 178 posts #11

still it shows error for me :

Are u human? ".$question." = in the registration page:

my code is :

function regSimpleAuth(){ $num1 = rand(1,20); $num2 = rand(1,20); $ans = $num1 + $num2; return array('question'=>'".$question."'); }

$auth = regSimpleAuth(); $_SESSION['ans'] = $auth['answer']; echo "Are u human? ".$auth['question']." = "; echo "<input type="text" name="authSum" value="?" size="3" maxlength="3"/> ";

anybody can fix it please

CreativityKills Lead · 833 posts #12

bijaybd wrote: still it shows error for me :

Are u human? ".$question." = in the registration page:

my code is :

function regSimpleAuth(){ $num1 = rand(1,20); $num2 = rand(1,20); $ans = $num1 + $num2; return array('question'=>'".$question."'); }

$auth = regSimpleAuth(); $_SESSION['ans'] = $auth['answer']; echo "Are u human? ".$auth['question']." = "; echo "<input type="text" name="authSum" value="?" size="3" maxlength="3"/> ";

anybody can fix it please

function regSimpleAuth(){
$num1 = rand(1,20); $num2 = rand(1,20);
$ans = $num1 + $num2;
$auth['question'] = "$num1 + $num2";
$auth['answer'] = $num1 + $num2;
return $auth;
}

$auth = regSimpleAuth();
$_SESSION['ans'] = $auth['answer'];
echo "Are u human?<br/>".$auth['question']." = ";
echo "<input type=\"text\" name=\"authSum\" value=\"?\" size=\"3\" maxlength=\"3\"/><br/>";

That shud defo work. If u have validation problems, go to the top of page(s) wher u have d script, and add

session_start();

bijaybd Developer · 178 posts #13

not working for me in the last step after entering it continuesly showing error :

my code is this can someone fix it :

in dbconfig.php file : function regSimpleAuth(){ $num1 = rand(1,20); $num2 = rand(1,20); $ans = $num1 + $num2; $auth['question'] = "$num1 + $num2"; $auth['answer'] = $num1 + $num2; return $auth; }

here is the register page :

$auth = regSimpleAuth(); $_SESSION['ans'] = $auth['answer']; echo "Are u human?* ".$auth['question']." = "; echo "<input type="text" name="authSum" value="" size="3" maxlength="3"/> ";

echo "<anchor>»Register"; echo "<postfield name="authSum" value="$(authSum)"/>\n"; echo "</anchor>";

and here is the 2nd proccessing in the same registration page :

if($_POST['authSum']!= $_SESSION['ans']){ echo "The Human Varification code is wrong please enter the varification code again to register.Example : 4+15=19 the answer should be like this."; echo " </card></wml>"; ob_end_flush(); exit(); }

so where do i making the mistake help me

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close