时间:2021-07-01 10:21:17 帮助过:7人阅读
输出图像
session_start();
for($i=0; $i<4; $i++){
$rand.= dechex(rand(1,15));
}
$_SESSION[check_pic]=$rand;
//echo $_SESSION[check_pic];
// 设置图片大小
$im = imagecreatetruecolor(100,30);
// 设置颜色
$bg=imagecolorallocate($im,0,0,0);
$te=imagecolorallocate($im,255,255,255);
// 把字符串写在图像左上角
imagestring($im,rand(5,6),rand(25,30),5,$rand,$te);
//
session_start();
if(isset($_POST[check]))
{
if($_POST[check] == $_SESSION[check_pic])
{
// echo "验证码正确".$_SESSION[check_pic];
require("dbinfo.php");
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$content = $_POST['content'];
$date = date("Y-m-d h:m:s");
// 连接到 MySQL 服务器
$connection = mysql_connect ($host, $username, $password);
if (!$connection)
{
die('Not connected : ' . mysql_error());
}
// 设置活动的 MySQL 数据库
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected)
{
die ('Can\'t use db : ' . mysql_error());
}
// 向数据库插入数据
$query = "insert into table (nowamagic_name, nowamagic_email, nowamagic_website, nowamagic_content, nowamagic_date) values ('$name','$email','$website','$content','$date')";
$result = mysql_query($query);
if($result)
{
echo "";
}
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
}
else
{
echo "";
}
}
?>