Webmaster Forum


Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 04-15-2012, 10:21 AM
Junior Member
 
Join Date: 03-11-12
Posts: 18
iTrader: 0 / 0%
Sql injection?

Hello

Just a quick question, Ive something like this for escape from the dangerous sql characters.
Code:
function quote_smart($value, $handle) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value, $handle) . "'"; } return $value; }
my question is do i have to add this into every pages or just for the login page?

thank you for your time.
 
Reply With Quote
  #2 (permalink)  
Old 04-15-2012, 02:59 PM
Junior Member
 
Join Date: 04-13-12
Posts: 23
iTrader: 0 / 0%
You should use it on every page that allows the user to type in information that will be stored in the database.
 
Reply With Quote
  #3 (permalink)  
Old 04-15-2012, 04:34 PM
Junior Member
 
Join Date: 03-11-12
Posts: 18
iTrader: 0 / 0%
em...so basically it will be on every pages as I have a search box on every pages...
 
Reply With Quote
  #4 (permalink)  
Old 04-15-2012, 04:37 PM
ScriptMan's Avatar
Super Moderator
 
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,082
iTrader: 4 / 100%
Only if the searches are entered into the DB. Injection happens mostly when you others enter data. Reading poses minimal problems if any.
__________________
SEO does not mean Spam Everywhere Online
Scriptman's Playhouse || Ramblings from an old man
2013 resolution: Don't feed trolls
ScriptMan
 
Reply With Quote
  #5 (permalink)  
Old 04-16-2012, 12:29 AM
nemrod's Avatar
v7n Mentor
 
Join Date: 12-21-10
Location: Sweden
Posts: 461
iTrader: 0 / 0%
Quote:
Originally Posted by mikewertheim View Post
You should use it on every page that allows the user to type in information that will be stored in the database.
Quote:
Originally Posted by ScriptMan View Post
Only if the searches are entered into the DB. Injection happens mostly when you others enter data. Reading poses minimal problems if any.
The search query will naturally need to be used in a query against the database to perform the search, whether it's SELECT or INSERT is really quite irrelevant, it's subject to injection as long as you use user input in a query.

Quote:
Originally Posted by yy885 View Post
em...so basically it will be on every pages as I have a search box on every pages...
Indeed. You should use an abstraction layer for your SQL queries though, so it's not any work if done properly from the start. If you don't have that the easy way is to make a file such as this:
PHP Code:
<?php
    
function escape($var) {
        
// here you can check the type or specific keys or whatever you want but generally just this is sufficient so secure it for usage in queries:
        
return mysql_real_escape_string($var); // again, you shouldn't really use static mysql_ functions but switch to an abstraction layer
    
}
    
$_POST array_map('escape'$_POST);
    
$_GET array_map('escape'$_GET);
?>
You can then include that file (say, escape.php) in all files and you'll be set. That will escape any and all user input - if you have input you don't want to escape for some reason or another remove the array_map and escape() manually per variable.

edit: speaking of includes, why do you have the search in multiple files? Just put it in a search-widget.php or whatever and include that file where it's supposed to be.
 
Reply With Quote
  #6 (permalink)  
Old 04-16-2012, 02:23 AM
JohnnyS's Avatar
Contributing Member
 
Join Date: 07-05-11
Location: philippines
Posts: 312
iTrader: 0 / 0%
Quote:
Originally Posted by yy885 View Post
Hello

Just a quick question, Ive something like this for escape from the dangerous sql characters.
Code:
function quote_smart($value, $handle) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value, $handle) . "'"; } return $value; }
my question is do i have to add this into every pages or just for the login page?

thank you for your time.
yes, i think you should.
not just on the login page, but in all pages would be better..

it's an excellent practice to clean-up every text that is passed through a query to prevent sql injection..
 
Reply With Quote
  #7 (permalink)  
Old 04-16-2012, 03:35 AM
ScriptMan's Avatar
Super Moderator
 
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,082
iTrader: 4 / 100%
Nemrod is right. Absolutely right.

My mind was still on page 92 of form 1040, down by 1 run , 3 balls, two strikes, 2 outs and bottom of the ninth.
__________________
SEO does not mean Spam Everywhere Online
Scriptman's Playhouse || Ramblings from an old man
2013 resolution: Don't feed trolls
ScriptMan
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL injection gnznroses Coding Forum 4 03-05-2008 10:17 AM
Injection Effect Mong Google Forum 1 08-12-2006 08:59 PM
sql injection help snout Coding Forum 21 04-28-2006 09:25 PM
PHP and SQL injection Limit Coding Forum 5 12-25-2004 02:35 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 11:19 PM.
Powered by vBulletin
Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.