Bu PHP ve MySQL komut hangisi akıllıca güvenli güvenlik?

1 Cevap php

Script 1 güvenli mi?

";
 }
 else
 {
  queryMysql("CREATE TABLE $name($query)");
  echo "Table '$name' created
"; } } function tableExists($name) { $result = queryMysql("SHOW TABLES LIKE '$name'"); return mysql_num_rows($result); } function queryMysql($query) { $result = mysql_query($query) or die(mysql_error()); return $result; } function destroySession() { $_SESSION=array(); if (session_id() != "" || isset($_COOKIE[session_name()])) setcookie(session_name(), '', time()-2592000, '/'); session_destroy(); } function sanitizeString($var) { $var = strip_tags($var); $var = htmlentities($var); $var = stripslashes($var); return mysql_real_escape_string($var); } function showProfile($user) { if (file_exists("$user.jpg")) echo "img src='$user.jpg' border='1' align='left' />"; $result = queryMysql("SELECT * FROM rnprofiles WHERE user='$user'"); if (mysql_num_rows($result)) { $row = mysql_fetch_row($result); echo stripslashes($row[1]) . "
"; } } ?>

veya komut 2 güvenlidir?

MySQL Error: " . mysql_error());

  // Print a message to the user, include the footer, and kill the script.
  include ('./includes/footer.htm');
  exit();

 } // End of mysql_select_db IF.

} else { // If it couldn't connect to MySQL.

 // Print a message to the user, include the footer, and kill the script.
 trigger_error("Could not connect to MySQL!\n
MySQL Error: " . mysql_error()); include ('./includes/footer.htm'); exit(); } // End of $dbc IF. // Create a function for escaping the data. function escape_data ($data) { // Address Magic Quotes. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } // Check for mysql_real_escape_string() support. if (function_exists('mysql_real_escape_string')) { global $dbc; // Need the connection. $data = mysql_real_escape_string (trim($data), $dbc); } else { $data = mysql_escape_string (trim($data)); } // Return the escaped value. return $data; } // End of function. ?>

1 Cevap

Ne. Her ikisi de tutarsız ve veritabanına almak için filtresiz veri opertunities sağlar.

Filtreleme isteğe bağlı değildir.

There shouldn't be a way to run a query without filtering taking place. If you're using php 5.2.x, use the SPL Filter functions to sanitize data.

Ile bir veri soyutlama katmanı yapmak için bu çok daha kolay hale getirir. Ben Zend Framework Zend_Db ve Zend_Db_Table sınıfları seviyorum. Bunlar için dokümanlar eylem mümkün olan en iyi kullanımını gösterir somut örnekleri var.

Sizin iki komut, ben 1. almak istiyorum. Bu fonksiyon-ized kod komut # 2 şeyler daha korumak için çok daha kolay olacaktır.