Jump to content

escaping data in PHP 4


yoda69

Recommended Posts

So, just to get this clear.

 

In php 4

If i use a form and pass information in GET or POST it is automatically escaped and I don't need to do anything else about the data.

 

if that is the case would you recommend me any other or additional procedures to protect my database from SQL injections attacks?

 

Tnx,

Link to comment
Share on other sites

The automatic esacping that you speak of is caused by magic_quotes_gpc, an ini directive. nothing to do with the version of php you are using. This used to be on by default, it is however slowly being outlawed. Pretty sure it will be gone or at least off by default in php6.

 

Anyway... to my point. You don't want to escape data again if this directive is on. So, before using mysql_real_esacpe_string, check. eg;

 

<?php

  if (!get_magic_quotes_gpc()) {
    $data = mysql_real_escape_string($_POST['data']);
  } else {
    $data = $_POST['lastname'];
  }

?>

Link to comment
Share on other sites

just a little add on there thorpey!

 

if security is what you were after in teh realm of escaping then you need to do this...

<?php

  if (!get_magic_quotes_gpc()) {
    $data = mysql_real_escape_string($_POST['data']);
  } else {
    $data = mysql_real_escape_string(strip_slashes($_POST['lastname']));
  }

?>

 

a minor but very important addition...

 

for a fuller picture look at example 1428 http://uk.php.net/manual/en/function.mysql-real-escape-string.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.