Hey all,
I am trying to get a visual image confirmation script working, to generate images for sign-up confirmation purposes, to help prevent spam bots from registering on a registration form I have.
So here is the code on the registration page, thus far:
And here is the code in visual.php:
When I go to view register.php in a web browser, the image is broken. It doesn't show up. So when I click to "view image", I get the following error: The image โhttp://localhost/domain/visual.php?confirm_ses=(randomly generated characters)โ cannot be displayed, because it contains errors.
Any idea what's going on, and how I can get this to work?
Thanks,
David
I am trying to get a visual image confirmation script working, to generate images for sign-up confirmation purposes, to help prevent spam bots from registering on a registration form I have.
So here is the code on the registration page, thus far:
Code:
<?PHP
/*
This code is taken from phpBB 2.0.21. It is meant to be a standalone registration.
*/
define('IN_PHPBB', true);
$phpbb_root_path = './forums/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_PROFILE);
init_userprefs($userdata);
//
// End session management
//
// session id check
if (!empty($HTTP_POST_VARS['sid']) || !empty($HTTP_GET_VARS['sid']))
{
$sid = (!empty($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : $HTTP_GET_VARS['sid'];
}
else
{
$sid = '';
}
//
// Set default email variables
//
$script_name = preg_replace('/^/?(.*?)/?$/', '1', trim($board_config['script_path']));
$script_name = ( $script_name != '' ) ? $script_name . '/profile.'.$phpEx : 'profile.'.$phpEx;
$server_name = trim($board_config['server_name']);
$server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
$server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
$server_url = $server_protocol . $server_name . $server_port . $script_name;
// -----------------------
// Page specific functions
//
function gen_rand_string($hash)
{
$rand_str = dss_rand();
return ( $hash ) ? md5($rand_str) : substr($rand_str, 0, 8);
}
//
// End page specific functions
// ---------------------------
?>
<html>
<head>
<title>Students in Action Registration</title>
</head>
<body bgcolor="#FFFFFF">
<form action="forums/profile.php" method="post">
This is a TEST!
<?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.
function random_str ($len)
{
$ch = "ABCDEFGHJKLMNPQRSTUVWXYZ1234567890";
$l = strlen ($ch) - 1;
$str = "";
for ($i=0; $i < $len; $i++)
{
$x = rand (0, $l);
$str .= $ch[$x];
}
return strtolower ($str);
}
$ses = random_str(16);
?>
<form method="get" action="register.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>
</form>
</body>
</html>
And here is the code in visual.php:
Code:
<?php
function random_str ($len)
{
$ch = "ABCDEFGHJKLMNPQRSTUVWXYZ1234567890";
$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 = 'database';
$db_hostname = 'localhost';
$db_username = 'username';
$db_password = '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 ('(anti-spam-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);
?>
When I go to view register.php in a web browser, the image is broken. It doesn't show up. So when I click to "view image", I get the following error: The image โhttp://localhost/domain/visual.php?confirm_ses=(randomly generated characters)โ cannot be displayed, because it contains errors.
Any idea what's going on, and how I can get this to work?
Thanks,
David







