code_junkie

Worst PHP practice found in your experience?

Nov 11th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. mysql_query('SELECT * FROM users WHERE user = '.$_POST['user']);
  2.  
  3. $_REQUEST['anything']
  4.  
  5. if (some_condition) {
  6. return false;
  7. error_log('some error message');
  8. }
  9.  
  10. // Load configuration settings.
  11. require_once(implode(DIRECTORY_SEPARATOR, array(
  12. SF_ROOT_DIR,
  13. 'apps',
  14. SF_APP,
  15. 'config',
  16. 'config.php'
  17. ));
  18.  
  19. if ($condition) {}
  20. else {
  21. // something
  22. }
  23.  
  24. if ($condition) {
  25. $var = 'foo';
  26. } else {
  27. $var = 'foo';
  28. }
  29.  
  30. function getAttributes(&$a_oNode)
  31. {
  32. $l_aAttributes = $a_oNode->attributes();
  33. if ($l_aAttributes === NULL)
  34. return array();
  35.  
  36. $l_iCount = count($l_aAttributes);
  37. $l_i = 0;
  38.  
  39. for ($l_i = 0; $l_i < $l_iCount; $l_i++)
  40. {
  41. $l_aReturn[$l_aAttributes[$l_i]->name()] = $l_aAttributes[$l_i]->value();
  42. }
  43.  
  44. return $l_aReturn;
  45. }
  46.  
  47. function getText(&$a_oNode)
  48. {
  49. $l_aChildren = $a_oNode->child_nodes();
  50. if ($l_aChildren === NULL)
  51. return NULL;
  52.  
  53. $l_szReturn = "";
  54.  
  55. $l_iCount = count($l_aChildren);
  56. for ($l_i = 0; $l_i < $l_iCount; $l_i++)
  57. {
  58. if ($l_aChildren[$l_i]->node_type() == XML_TEXT_NODE)
  59. $l_szReturn .= $l_aChildren[$l_i]->node_value();
  60. }
  61.  
  62. if (strlen($l_szReturn) > 0)
  63. return $l_szReturn;
  64.  
  65. return NULL;
  66. }
  67.  
  68. if ($condition)
  69. foo();
  70.  
  71. $sql = "SELECT * FROM attendance_exceptions";
  72. $found = false;
  73.  
  74. ...
  75.  
  76. $appendSql = " AND YEAR(event_time) = '$_POST['year']' AND MONTH(event_time) = '$_POST['month']' AND DAY(event_time) = '$_POST['day']'";
  77. $temp = array($sql, $appendSql);
  78. $sql = join($temp);
  79. $found=true;
  80.  
  81. function verifyQuery($sql, $con) {
  82. if (!mysql_query($sql, $con)) {
  83. echo "Error occured in verifyQuery() in sqlfunctions.php <br>";
  84. echo "SQL sent : ";
  85. echo $sql;
  86. echo "<br>Database report: <br>";
  87. die('Error: ' . mysql_error());
  88. }
  89. return mysql_query($sql);
  90. }
  91.  
  92. <?php
  93.  
  94. // Obviosly relying on register globals!
  95. switch($page) {
  96.  
  97. case cart:
  98. echo '<html><head>...</head><body>'.
  99. some random application logic, including SQL, of course! .
  100. '</body></html>';
  101. break;
  102.  
  103. case checkout:
  104. echo '<html><head>...</head><body>'.
  105. even more random application logic, including SQL, of course! .
  106. '<form><input type="hidden" name="total" value="X"></body></html>';
  107. break;
  108.  
  109. case complete:
  110. echo '<html><head>...</head><body>'.
  111. and again, some random application logic, including SQL, of course! .
  112. '</body></html>';
  113. break;
  114.  
  115. case error:
  116. echo '<html><head>...</head><body>'.
  117. some random application logic, including SQL, of course! .
  118. '</body></html>';
  119. break;
  120.  
  121. // Show the home page
  122. default:
  123. echo '<html><head>...</head><body>'.
  124. show the home page, if you really don't know what else to do.....
  125. '</body></html>';
  126. break;
  127.  
  128. ?>
  129.  
  130. $str = file_get_contents("db-info.php");
  131.  
  132. $str = str_replace("<?", "", $str);
  133. $str = str_replace("?>", "", $str);
  134.  
  135. eval($str);
  136.  
  137. $url_parts = explode("/",ereg_replace("(.php|.html|.htm)", "", $_SERVER['PHP_SELF']));
Add Comment
Please, Sign In to add comment