Source codes, small scripts...

Started on the old forum in June 2006 · view the original in the archive · old links redirect here

124 replies · 52,842 views · started 20 years ago · 1 min read

TL;DR · summary of 124 replies
  • - The scripts and codes related to redirection, user online status, image resizer, PHP file upload script, and environment variables were discussed.
  • - No specific fix or code approach was provided for the Wap Useronline Sql tables script or the randomize banners script.
  • - The existence of a function to detect spammer emails was mentioned but no detailed code approach was given.

Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.

24 participants
i0nutzxp Developer · 150 posts #121

PHP browser Debugger

Function to be included in functions list:

function console_log()
{
    $args = func_get_args();        
    $argsSize = count($args);
        
    if ($argsSize == 0)
    {
        return false;
    }
    
    if ($argsSize == 1)
    {
        $output = sprintf($args[0]);
    }
    else
    {
        $output = call_user_func_array('sprintf', $args);
    }         
    $output = str_replace(array("\r", "\n"), '', $output);    
    echo '<script type="text/javascript"> if ( ! window.console) console = {}; console.log = console.log || function(name, data){}; console.log("'.$output.'"); </script>';                           
}

Usage:

class Test
{
    private $test = 2;
}

console_log(print_r(new Test(), true));

$day = 21;
console_log("%d %s %d", $day, 'Dec', 2004); 
console_log("Code at line %d .", __LINE__);
console_log(print_r($days, true));

echo 'Hellow world!';

Just open browser console to use this tool.

<?php unlink('World/Europe/Romania.country'); ?>
kiss Senior · 294 posts #122

Anti Xss

 function anti_xss( $string, $type )
 {
  switch ( $type ) {
   case "int":
    $string = ( int )$string ;
    break ;
   case "mysql":
    $string = mysql_real_escape_string( $string ) ;
    break ;
   case "nohtml":
    $string = htmlentities( $string , ENT_QUOTES, "UTF-8" ) ; // or ISO-8859-2 for romanian charset
    break ;
  }
  return $string ;
 }

//- int, use it for parameters with numbers. Example: 
$uid = anti_xss($_GET["uid"], "int"); // profil.php?uid=25

//- mysql, use it for parameters with data base. Example: 
$pass = anti_xss($_POST["pass"], "mysql"); // INSERT INTO `x_table` WHERE `pass`='".$pass."'

//- nohtml, use it for showing information on site. Example: 
$text = "Playromania it kid and write <script>alert("Im nobody and a lost soul on the net :D");</script>";
echo anti_xss($text, "nohtml");

www.inbuzunar.mobi -Your mobile portal pocket

arnage Lead · 811 posts #123

Random readable password

function random_readable_pwd($length=10){
 
    // the wordlist from which the password gets generated 
    // (change them as you like)
    $words = 'dog,cat,sheep,sun,sky,red,ball,happy,ice,';
    $words .= 'green,blue,music,movies,radio,green,turbo,';
    $words .= 'mouse,computer,paper,water,fire,storm,chicken,';
    $words .= 'boot,freedom,white,nice,player,small,eyes,';
    $words .= 'path,kid,box,black,flower,ping,pong,smile,';
    $words .= 'coffee,colors,rainbow,plus,king,tv,ring';
 
    // Split by ",":
    $words = explode(',', $words);
    if (count($words) == 0){ die('Wordlist is empty!'); }
 
    // Add words while password is smaller than the given length
    $pwd = '';
    while (strlen($pwd) < $length){
        $r = mt_rand(0, count($words)-1);
        $pwd .= $words[$r];
    }
 
    // append a number at the end if length > 2 and
    // reduce the password size to $length
    $num = mt_rand(1, 99);
    if ($length > 2){
        $pwd = substr($pwd,0,$length-strlen($num)).$num;
    } else { 
        $pwd = substr($pwd, 0, $length);
    }
 
    return $pwd;
 
}

random_readable_pwd(10) => returns something like: pingwater6, radiohap28, sunwhite84, happykid44, etc...

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
arnage Lead · 811 posts #124

I just got idea from this topic: http://coding-talk.com/f14/count-files-in-spicyfm-script-10983/

function count_files($dir_path = '', $what = '') {
	$count = count(glob($dir_path.'/*.'.$what.''));
	return echo 'There is '.($count > 1 
			? '<b>'.$count.'</b> files' : ($count == 1 
			? '<b>one</b> file' : '<b>no files</b>')).' in '.dirname($dir_path).'<br/>'.PHP_EOL;
}
//
count_files('downloads/images', 'jpg');
count_files('downloads/images', 'jpg|jpeg');
count_files('downloads/videos', '3gp');
count_files('downloads/videos', '3gp|mp4');
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
arnage Lead · 811 posts #125

Easy way to make every first letter in a sentence uppercase.

function capsfirst_sentence($string) {

	return empty($string) ? '' : preg_replace('/\b(\w)/e', 'strtoupper("$1")', $string);

}
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close