Prevent PHP script from being flooded

You can use memcache to do this .. Simple Demo Script $memcache = new Memcache (); $memcache->connect ( ‘localhost’, 11211 ); $runtime = $memcache->get ( ‘floodControl’ ); if ((time () – $runtime) < 2) { die ( “Die! Die! Die!” ); } else { echo “Welcome”; $memcache->set ( “floodControl”, time () ); } This is … Read more

UPDATE with ORDER BY and LIMIT not working in MYSQL

Usually you can use LIMIT and ORDER in your UPDATE statements, but in your case not, as written in the MySQL Documentation 12.2.10. UPDATE Syntax: For the multiple-table syntax, UPDATE updates rows in each table named in table_references that satisfy the conditions. In this case, ORDER BY and LIMIT cannot be used. Try the following: … Read more

Only allow certain characters to be entered in html textinput

You can change your input text as below: <input type=”text” pattern=”[a-zA-Z0-9!@#$%^*_|]{6,25}” /> So the code changes look like below: <form action=”#” method=”get”> User Name:<br /> <input type=”text” pattern=”[a-zA-Z0-9!@#$%^*_|]{6,25}” /><br /> Password:<br /> <input type=”password” /><br /> <input type=”submit” value=”Log In” /> </form> This will work without using JavaScript. pattern can be used instead. It is … Read more

Mongodb aggregation pipeline how to limit a group push

Suppose the bottom left coordinates and the upper right coordinates are respectively [0, 0] and [100, 100]. From MongoDB 3.2 you can use the $slice operator to return a subset of an array which is what you want. db.collection.aggregate([ { “$match”: { “loc”: { “$geoWithin”: { “$box”: [ [0, 0], [100, 100] ] } }} … Read more