Jump to content

image verification


shortybookit

Recommended Posts

i am trying to figure out an image verification for a log in form just testing it so there is nothing else on the form but any input?

 

here it all is

 

i get an error when i try to view the image on visual.php

 

it all works but no one can see the image

i know it works because instead of 5 random char i changed it to 1 and i changed the char to choose from to 1

i typed it in and worked but no one can guess what a 5 letter random verification is

 

HELPPP

thanks much

 

 

 

CREATE TABLE `visual_confirm` (

  `confirm_ses` varchar(16) NOT NULL default '',

  `confirm_val` varchar(5) NOT NULL default '',

  `confirm_time` int(10) unsigned NOT NULL default '0',

  PRIMARY KEY  (`confirm_ses`)

) TYPE=MyISAM;

 

 

(visual.php)

 

<?php

function random_str ($len)

{

$ch = "ABCDEF1234567890";

$l = strlen ($ch) - 1;

$str = "";

for ($i=0; $i < $len; $i++)

{

$x = rand (0, $l);

$str .= $ch[$x];

}

return strtolower ($str);

}

 

 

// fill with MySQL configuration

$db_name = 'dbname';

$db_hostname = 'localhost';

$db_username = 'root';

$db_password = '';

 

if (!$dbh=mysql_pconnect ($db_hostname,$db_username, $db_password))

{ echo mysql_error (); exit; }

mysql_select_db($db_name, $dbh);

 

// init vars

$confirm_ses = $_GET['confirm_ses'];

$t = random_str (5);

$w = 45;

$h = 21;

$now = mktime ();

$was = mktime () - 600;

 

mysql_query ("INSERT INTO visual_confirm VALUES ('$confirm_ses', '$t', '$now')");

mysql_query ("DELETE FROM visual_confirm WHERE confirm_time < $was");

 

header ('Content-Type: image/png');

$gb = imagecreate ($w, $h);

$bgc = imagecolorallocate ($gb, 255, 255, 255);

$fgc = imagecolorallocate ($gb, 0, 0, 0);

$grc = imagecolorallocate ($gb, 200, 200, 200);

 

imagestring ($gb, 5, 0, 5, $t, $fgc);

imagePNG ($gb);

imagedestroy ($gb);

?>

 

Explanation

 

<?php

function random_str ($len)

{

$ch = "ABCDEF1234567890";

$l = strlen ($ch) - 1;

$str = "";

for ($i=0; $i < $len; $i++)

{

$x = rand (0, $l);

$str .=

$ch[$x];

}

return strtolower ($str);

}

 

his will create a random string.

 

// init vars

$confirm_ses = $_GET['confirm_ses'];

 

Get confirmation session id from $_GET['confirm_ses'].

 

$t = random_str (5);

 

Create a five random characters string.

 

$w = 45;

$h = 21;

 

Image size for output.

 

$now = mktime ();

$was = mktime () - 600;

 

mysql_query ("INSERT INTO visual_confirm VALUES ('$confirm_ses', '$t', '$now')");

mysql_query ("DELETE FROM visual_confirm WHERE confirm_time < $was");

 

This will create a row in visual_confirm table, and also delete old rows.

 

header ('Content-Type: image/png');

$gb = imagecreate ($w, $h);

$bgc = imagecolorallocate ($gb, 255, 255, 255);

$fgc = imagecolorallocate ($gb, 0, 0, 0);

$grc = imagecolorallocate ($gb, 200, 200, 200);

 

imagestring ($gb, 5, 0, 5, $t, $fgc);

imagePNG ($gb);

imagedestroy ($gb);

?>

 

Create visual confirmation image.

Usage

To display it use this script:

(index.php)

 

<?php

// NOTE: if you have CL, you can use the following line:

// require 'includes/init.php';

// otherwise, copy & paste random_str() function from visual.php above.

 

$ses = random_str (16);

?>

 

<form method="get" action="confirm.php">

<input type="hidden" name="confirm_ses" value="<?php echo $ses;?>">

Confirmation code: <img src="visual.php?confirm_ses=<?php echo$ses;?>"><br>

Enter confirmation code: <input type="text" name="confirm_val"><br>

<input type="submit">

</form>

 

This will call visual.php, and also add hidden value confirm_ses to form.

 

To verify if the user entered a correct confirmation code, use this:

(confirm.php)

 

<?php

// fill with MySQL configuration

$db_name = 'dbname';

$db_hostname = 'localhost';

$db_username = 'root';

$db_password = '';

 

if (!$dbh=mysql_pconnect ($db_hostname, $db_username, $db_password)) { echo mysql_error (); exit; }

mysql_select_db($db_name, $dbh);

 

$confirm_ses = $_GET['confirm_ses'];

$confirm_val = $_GET['confirm_val'];

$res = mysql_query ("SELECT * FROM visual_confirm WHERE confirm_ses = '$confirm_ses' LIMIT 1");

$row = mysql_fetch_array ($res);

if (empty ($row)) die ('Invalid confirm_ses ID');

if ($row['confirm_val'] == $confirm_val)

die ('Success!');

else

die ('Wrong confirm_val. Try again!');

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/42886-image-verification/
Share on other sites

Ok ... picture is not shown...

 

Use this to get the image:

<img src="path_to_generator.php">

 

 

First make blank file (test.php or smth) and put inside to show this picture..

 

If picture isn't shown ... Than there's smth wrong with the code.

 

Tell us results...

 

Best regards.

Link to comment
https://forums.phpfreaks.com/topic/42886-image-verification/#findComment-208339
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.