Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ereg format to prevent SQL injection

Status
Not open for further replies.

shartken

Programmer
Jan 3, 2005
3
US
I am trying to run the following function to prevent sql injection in the body of a forum message:

<?php
ereg((SELECT\s[\w\*\)\(\,\s]+\sFROM\s[\w]+)|
(UPDATE\s[\w]+\sSET\s[\w\,\'\=]+)|
(INSERT\sINTO\s[\d\w]+[\s\w\d\)\(\,]*\sVALUES\s\([\d\w\'\,\)]+)|
(DELETE\sFROM\s[\d\w\'\=]+), "SELECT * FROM table");
?>

But nothing happens. What I want to do is censor out SQL commands in a message body. I can't just take out words like SELECT or DELETE as they might be used legitamately. So I came up with this idea.
If someone has an easier away around SQL injection in a forum, just let me know.
 
Wait, I am using PHP v3 and I can't run this function. If magic quotes are turned on, do I even need to do this. Or should I just use the strip_slashes functioN?
 
what about using htmlentities as well to avoid js scrpting attacks on the db?

Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top