Example
The code is as follows |
Copy Code |
function Getrepeatdata (input) { var arr = input; var rdata = {}; for (var i in arr) { &nbs p; var c = arr[i]; rdata1? (rdata1++): (rdata1= 1) } for (var k in rdata) { if (rdata[k ] {///Word repeat more than 4 times, returns false return false }else{ >=4 return True } } } var content=$ (' #content '). Val (); Var repeat= Getrepeatdata (content); var regimg=/(https|http|ftp): \/\/) {1}.+?. (jpg|gif|jpeg|png) $/gi; if (!regimg.test (content)) {//filter picture address in content if (repeat==false) { alert ("Pro, Do not irrigation yo ~ "); return false; } |
Analysis Although this can be done some processing but if we do not go through this code, but we do a submission page is not used, so we need to use PHP to deal with, such as adding a verification code can be solved.
Submit the page code as follows a.php code as follows:
The code is as follows |
Copy Code |
<form id= "Form1" Name= "Form1" method= "Post" action= "t2.php" > <p> description <input type= "text" name= "Titile"/> </p> <p> <input type= "Submit" name= "Submission" value= "submitted"/> </p> </form> <?php Setcookie ("Onlypost", ' t '); Set the cookie to bring the time value. Like some of the forums to prevent irrigation can put some of your basic information into the inside. ?> The processing page b.php code is as follows: <?php if ($_cookie[' onlypost '] = = ' t ') { Print_r ($_cookie); Processing of committed content if validation succeeds print "OK"; Setcookie ("Onlypost", ' f '); Change the cooike value to delete it too } ?> |
Body
As a disadvantage of processing: If the client prohibits cookies, this method will have no effect, please note.
We can use PHP MySQL to solve
Database for jokes, table for jokes, add a joke for example
MySQL Form submission page:
The code is as follows |
Copy Code |
<HTML> <HEAD> <TITLE> our List of jokes </TITLE> </HEAD> <BODY>
<?php Session_Start (); Enable session $timetime = time (); $key = "Sess_". $time; Generate a random session key based on time $_session[$key] = $time; Set the value of the session ?>
<form action= "Input.php?tjid=1" method=post> <p>type your joke here:<br> <textarea name= "Joketext" rows=10 cols=40 wrap></textarea><br> Pass the key of the session to the server-side processing by hiding the form <input type= "hidden" name= session_key "value=" <?php echo $key;? > "/> <input type=submit name= "Submitjoke" value= "SUBMIT" > </FORM>
</BODY> </HTML>
Processing page: <HTML> <HEAD> <TITLE> our List of jokes </TITLE> </HEAD> <BODY> To connect to a database: <?php $dbcnx =mysql_connect ("localhost", "root", "Hu Jintao"); if (! $dbcnx) { Echo ("<p>unable to connect to".) "Database server at this time.</p>"); Exit (); } Select the Jokes database if (! @mysql_select_db ("jokes")) { Echo ("<p>unable to locate the joke"). "Database at this time.</p>"); Exit (); } Start session: Session_Start (); $key = $_post[' Session_key ']; if (! $key | | $_session[$key]!= substr ($key, 5)) { If no session_key parameters are passed Or the number after the Session_key parameter value is truncated Sess_ does not match the session parameter value Unset ($_session[$key]); Delete Session value echo "Chu CuO la";//Then consider whether you want to prompt for an error, or go to another page Exit (); Terminate page code execution }
The following data write operations if ("SUBMIT" ==$_post["Submitjoke"]) { $sql = "INSERT into Jokes (joketext) VALUES (' $_post[joketext] ') "; if (mysql_query ($sql)) { Echo ("<p>your joke has been added.</p>"); } else { Echo ("<p>error adding submitted joke:". Mysql_error (). "</P>"); } Delete session after data operation is complete Unset ($_session[$key]); } ?>
Show jokes content: <P> Here are all the jokes in our database: </P> <BLOCKQUOTE> <?php $result = mysql_query ( "SELECT * from jokes"); if (! $result) { Echo ("<p>error performing Query:".) Mysql_error (). "</P>"); Exit (); } Display the text of each joke in a paragraph while ($row = Mysql_fetch_array ($result)) { Echo ("<P>" $row ["Joketext"]. "</P>"); } ?>
</BODY> </HTML> |