Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What's the right way to prevent SQL injection in PHP scripts?

user-image
Question ajoutée par Khadijah Shtayat , Technical Lead , Opensooq
Date de publication: 2013/09/08
Fadi Alkhateeb
par Fadi Alkhateeb , Senior Front End Developer , NexTwo

Use prepared statements and parameterized queries (PDO & Mysqli).

PDO : http://php.net/manual/en/book.pdo.php

MYsqli : http://php.net/manual/en/book.mysqli.php

 

You can see more informations about it here :

How to Prevent SQL Injection in PHP

 

Mohammad Ateieh
par Mohammad Ateieh , Software Engineering Manager , Bayt.com

in PDO and MySqli you can bind the parameters and then excute the query

another solution you can escape the parameters using "mysql_real_escape_string"

its all depends on what are you using to manipulate the sql statement

Arif Mohammad Mohiuddin
par Arif Mohammad Mohiuddin , Data Entry Chief & Manager , Mohammadia Enterprise

Stored Procedure

 

Muhammed Ajmal Seeraveetil
par Muhammed Ajmal Seeraveetil , Software Engineer , Wipro

Better always use XSS Filtering 

Asif Ahmad Rather
par Asif Ahmad Rather , Senior Software Engineer , Eresolute Consultant and Services pvt ltd.

the best and the simple way is use sql procedures and try to implement strict coding. dont b a loose coder. 

Mohammed Aldini
par Mohammed Aldini , Project Manager/Team Leader/Senior Software Engineer/System Analysis , TechBox Group

use mysql_escape_string function to avoid charectors for sql injection before the string with {} for example:"SELECT *FROM  `tablename`WHERE  fieldname = '{".mysql_escape_string($value)."}'"

Tanweer Ahmed
par Tanweer Ahmed , Application Developer , Department of Revenue,Registration and Land Reforms,Government of Jharkhand

Use Parameterized Query to prevent sql injection

mukhtar ahmed Ibrahim
par mukhtar ahmed Ibrahim , Software engineer , Norwegian tax administration

 

Best way to prevent sql injection is looking for correct input.  Use regular expressions and develop strategy for invalid input. Please remember pitfals. alternative representations. http://myhostname.com or http://194.71.105.29.

Biggest mistake:

.Not checking at all,

.Looking for incorrect input. 

Saad Ibrahim
par Saad Ibrahim , senior web developer , brandusocial

Beside The best things  that all Other developrs mention, the best thing u can do to avoid SQL injection, is FILTER ALL INPUTS , Nerver trust input from user.

Utilisateur supprimé
par Utilisateur supprimé

One of the ways is using magic quotes at server level. Another one is using the function addslashes for each input, although it's not really nice.

Junais Vaisyar
par Junais Vaisyar , End-User Support , KAUST

use mysql_escape_string function to avoid charectors for sql injection before the string

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?