How To Read External Files In WordPress
We often find ways by which we can read external files in safest way. Well, in this I am sharing the snippet which will let you read external files in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
<?php /** * sicheres einlesen externer Dateien */ private function URLreadFsock($host, $file, &$errstr, $successonly=true, $port=80, $timeout=10) { if (!function_exists('fsockopen')) { $errstr = 'fsockopen() unavailable'; return false; } if ($fp = @fsockopen($host, 80, $errno, $errstr, $timeout)) { $out = 'GET '.$file.' HTTP/1.0'." "; $out .= 'Host: '.$host." "; $out .= 'Connection: Close'." "; fwrite($fp, $out); $isHeader = true; $Data_header = ''; $Data_body = ''; $header_newlocation = ''; while (!feof($fp)) { $line = fgets($fp, 1024); if ($isHeader) { $Data_header .= $line; } else { $Data_body .= $line; } if (eregi('^HTTP/[\\.0-9]+ ([0-9]+) (.+)$', rtrim($line), $matches)) { list($dummy, $errno, $errstr) = $matches; $errno = intval($errno); } elseif (eregi('^Location: (.*)$', rtrim($line), $matches)) { $header_newlocation = $matches[1]; } if ($isHeader && ($line == " ")) { $isHeader = false; if ($successonly) { switch ($errno) { case 200: // great, continue break; default: $errstr = $errno.' '.$errstr.($header_newlocation ? '; Location: '.$header_newlocation : ''); fclose($fp); return false; break; } } } } fclose($fp); return $Data_body; } return null; } private function ParseURLbetter($url) { $parsedURL = @parse_url($url); if (!@$parsedURL['port']) { switch (strtolower(@$parsedURL['scheme'])) { case 'ftp': $parsedURL['port'] = 21; break; case 'https': $parsedURL['port'] = 443; break; case 'http': $parsedURL['port'] = 80; break; } } return $parsedURL; } private function _getVersionFile($url, &$error, $timeout=10, $followredirects=true) { $error = ''; $parsed_url = $this->ParseURLbetter($url); $alreadyLookedAtURLs[trim($url)] = true; while (true) { $tryagain = false; $rawData = $this->URLreadFsock(@$parsed_url['host'], @$parsed_url['path'].'?'.@$parsed_url['query'], $errstr, true, (@$parsed_url['port'] ? @$parsed_url['port'] : 80), $timeout); if (eregi('302 [a-z ]+; Location\\: (http.*)', $errstr, $matches)) { $matches[1] = trim(@$matches[1]); if (!@$alreadyLookedAtURLs[$matches[1]]) { // loop through and examine new URL $error .= 'URL "'.$url.'" redirected to "'.$matches[1].'"'; $tryagain = true; $alreadyLookedAtURLs[$matches[1]] = true; $parsed_url = $this->ParseURLbetter($matches[1]); } } if (!$tryagain) { break; } } if ($rawData === false) { $error .= 'Error opening "'.$url.'":'."\n\n".$errstr; return false; } elseif ($rawData === null) { // fall through $error .= 'Error opening "'.$url.'":'."\n\n".$errstr; } else { return trim($rawData); } // curl if (function_exists('curl_version')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); $rawData = curl_exec($ch); curl_close($ch); if (strlen($rawData) > 0) { $error .= 'CURL succeeded ('.strlen($rawData).' bytes); '; return trim($rawData); } $error .= 'CURL available but returned no data; '; } else { $error .= 'CURL unavailable; '; } // fopen $BrokenURLfopenPHPversions = array('4.4.2'); if (in_array(phpversion(), $BrokenURLfopenPHPversions)) { $error .= 'fopen(URL) broken in PHP v'.phpversion().'; '; } elseif (@ini_get('allow_url_fopen')) { $rawData = ''; $error_fopen = ''; ob_start(); if ($fp = fopen($url, 'rb')) { do { $buffer = fread($fp, 8192); $rawData .= $buffer; } while (strlen($buffer) > 0); fclose($fp); } else { $error_fopen .= trim(strip_tags(ob_get_contents())); } ob_end_clean(); $error .= $error_fopen; if (!$error_fopen) { $error .= '; "allow_url_fopen" succeeded ('.strlen($rawData).' bytes); '; return trim($rawData); } $error .= '; "allow_url_fopen" enabled but returned no data ('.$error_fopen.'); '; } else { $error .= '"allow_url_fopen" disabled; '; } return false; } |
Snippet Source/Credit: Snipplr
How To Remove Code Which Got Added For An iframe Injection In WordPress
The following snippet will let you remove the code which got added for an iframe injection. Before doing this, make sure you do backup all your data.
1 2 3 4 |
# FIND find . -type f | xargs grep -l '<iframe.*statanalyze.cn.*iframe' # REPLACE find . -type f -exec sed -i 's/<iframe.*statanalyze.cn.*iframe>//g' {} \; |
Snippet Source/Credit: WordPress.org
How To Remove Dashboard Widgets In WordPress
The following snippet will let you remove the dashboard widgets in your WordPress website. Paste the following into your functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function remove_dashboard_widgets() { global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } if (!current_user_can('manage_options')) { add_action('wp_dashboard_setup', 'remove_dashboard_widgets' ); } |
Snippet Source/Credit: WPRecipes.com
How To Replace The WordPress Generator
The following snippet will let you replace the WordPress generator.
1 2 3 4 5 6 |
// Remove the WordPress Generator function remove_generators() { return ''; } add_filter( 'the_generator', 'remove_generators' ); // Replace the WordPress Generator function change_generators() { return '<meta name="generator" content="WordPress" />'; } add_filter( 'the_generator', 'change_generators' ); |
Snippet Source/Credit: DevZone.fr
How To Reset A Query In WordPress
The following snippet will let you reset a query in WordPress.
1 2 3 4 |
// esempio in una ipotetica index.php // a fine pagina, dopo aver eseguito una o più // query_posts() personali <?php wp_reset_query(); get_sidebar(); get_footer(); ?> |
Snippet Source/Credit: Undolog.com