Source codes, small scripts...

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PHP browser Debugger

    Function to be included in functions list:
    PHP Code:
    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:

    PHP Code:
    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($daystrue));

    echo 
    'Hellow world!'
    Just open browser console to use this tool.
    <?php unlink('World/Europe/Romania.country'); ?>

    Comment


      Anti Xss

      PHP Code:
       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"); 
      Last edited by arnage; 06.09.12, 19:41.
      www.inbuzunar.mobi - Your mobile portal pocket

      Comment


        Random readable password

        PHP Code:
        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(0count($words)-1);
                
        $pwd .= $words[$r];
            }
         
            
        // append a number at the end if length > 2 and
            // reduce the password size to $length
            
        $num mt_rand(199);
            if (
        $length 2){
                
        $pwd substr($pwd,0,$length-strlen($num)).$num;
            } else { 
                
        $pwd substr($pwd0$length);
            }
         
            return 
        $pwd;
         

        random_readable_pwd(10) => returns something like: pingwater6, radiohap28, sunwhite84, happykid44, etc...
        <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

        Comment


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

          PHP Code:
          function count_files($dir_path ''$what '') {
              
          $count count(glob($dir_path.'/*.'.$what.''));
              return echo 
          'There is '.($count 
                      
          '<b>'.$count.'</b> files' : ($count == 
                      
          '<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

          Comment


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

            PHP Code:
            function capsfirst_sentence($string) {

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


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

            Comment

            Working...
            X