Checkcode.php generates a CAPTCHA picture, and a variable $_session[check_pic].
Copy Code code as follows:
?
Session_Start ();
For ($i =0 $i <4; $i + +) {
$rand. = Dechex (rand (1,15));
}
$_session[check_pic]= $rand;
Echo $_session[check_pic];
Set Picture size
$im = Imagecreatetruecolor (100,30);
Set color
$BG =imagecolorallocate ($im, 0,0,0);
$te =imagecolorallocate ($im, 255,255,255);
Write the string in the upper-left corner of the image
Imagestring ($im, Rand (5,6), Rand (25,30), 5, $rand, $te);
Output image
Header ("Content-type:image/jpeg");
Imagejpeg ($im);
?>
form.php
Code picture generated by Call
Copy Code code as follows:
<div class= "Bottomads" >
<fieldset class= "bottomads_quote" ><legend> message </legend>
<div class= "Ads" >
<form action= ". /utity/post.php "method=" POST "onsubmit=" return Chkinput (This) >
<input name= "name" type= "text"/> Your name
<input name= "Email" type= "text"/> Your mail
<input name= "website" type= "text"/> Your site
<textarea name= "Content" style= "width:340; height:150; " >
</textarea><br/>
<input type= "text" name= "check" ><br/>
<input type= "Submit" value= "submitted"/>
</form>
</div>
<BR clear= "both"/>
</fieldset>
Imagestring ($im, Rand (5,6), Rand (25,30), 5, $rand, $te); Use int imagestring (int im, int font, int x, int y, string s, int col); function, which is used to draw a horizontal string.
This function draws a horizontal string on the picture. The argument font is a glyph, set to 1 through 5 to use the default glyph. parameter x, Y is the string start coordinate. The contents of the string are placed on the parameter S. The parameter col represents the color of the string.
post.php
Compare $_post[check] with $_session[check_pic], and if equal, perform a database insert operation. If not equal, return to the previous page.
Copy Code code as follows:
<?php
Session_Start ();
if (Isset ($_post[check]))
{
if ($_post[check] = = $_session[check_pic])
{
echo "Verify code correct". $_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");
Connecting to the MySQL server
$connection = mysql_connect ($host, $username, $password);
if (! $connection)
{
Die (' Not connected: '. mysql_error ());
}
Setting up an active MySQL database
$db _selected = mysql_select_db ($database, $connection);
if (! $db _selected)
{
Die (' can\ ' t use DB: '. mysql_error ());
}
Inserting data into the database
$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 "<script>alert (' submitted successfully '); History.go ( -1);</script> ";
}
if (! $result)
{
Die (' Invalid query: '. mysql_error ());
}
}
Else
{
echo "<script>alert (' Authentication code error '); History.go ( -1);</script> ";
}
}
?>