Source codes, small scripts...

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

  • GumSlone
    replied
    php header();

    Here are some usefull headers,

    PHP Code:
    // See related links for more status codes
    
    // Use this header instruction to fix 404 headers
    // produced by url rewriting...
    header('HTTP/1.1 200 OK');
    
    // Page was not found:
    header('HTTP/1.1 404 Not Found');
    
    // Access forbidden:
    header('HTTP/1.1 403 Forbidden');
    
    // The page moved permanently should be used for
    // all redrictions, because search engines know
    // what's going on and can easily update their urls.
    header('HTTP/1.1 301 Moved Permanently');
    
    // Server error
    header('HTTP/1.1 500 Internal Server Error');
    
    // Redirect to a new location:
    header('Location: http://www.example.org/');
    
    // Redriect with a delay:
    header('Refresh: 10; url=http://www.example.org/');
    print 'You will be redirected in 10 seconds';
    
    // you can also use the HTML syntax:
    // <meta http-equiv="refresh" content="10;http://www.example.org/ />
    
    // override X-Powered-By value
    header('X-Powered-By: PHP/4.4.0');
    header('X-Powered-By: Brain/0.6b');
    
    // content language (en = English)
    header('Content-language: en');
    
    // last modified (good for caching)
    $time = time() - 60; // or filemtime($fn), etc
    header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
    
    // header for telling the browser that the content
    // did not get changed
    header('HTTP/1.1 304 Not Modified');
    
    // set content length (good for caching):
    header('Content-Length: 1234');
    
    // Headers for an download:
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="example.zip"'); 
    header('Content-Transfer-Encoding: binary');
    // load the file to send:
    readfile('example.zip');
    
    // Disable caching of the current document:
    header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Pragma: no-cache');
    
    // set content type:
    header('Content-Type: text/html; charset=iso-8859-1');
    header('Content-Type: text/html; charset=utf-8');
    header('Content-Type: text/plain'); // plain text file
    header('Content-Type: image/jpeg'); // JPG picture
    header('Content-Type: application/zip'); // ZIP file
    header('Content-Type: application/pdf'); // PDF file
    header('Content-Type: audio/mpeg'); // Audio MPEG (MP3,...) file
    header('Content-Type: application/x-shockwave-flash'); // Flash animation
    
    // show sign in box
    header('HTTP/1.1 401 Unauthorized');
    header('WWW-Authenticate: Basic realm="Top Secret"');
    print 'Text that will be displayed if the user hits cancel or ';
    print 'enters wrong login data'; 
    
    this is a copy and paste code from http://www.jonasjohn.de/snippets/php/headers.htm

    Leave a comment:


  • Anshul
    replied
    real IP address

    Code:
    function getIpAddress() {
    return (empty($_SERVER['HTTP_CLIENT_IP'])?(empty($_SERVER['HTTP_X_FORWARDED_FOR'])?
    $_SERVER['REMOTE_ADDR']:$_SERVER['HTTP_X_FORWARDED_FOR']):$_SERVER['HTTP_CLIENT_IP']);
    }
    usage

    Code:
    $ip=getIpAddress();

    Leave a comment:


  • sweetangel
    replied
    Originally posted by GumSlone View Post
    ANTI SQL INJECTION Function

    PHP Code:
    function check_injection()
      {
        $badchars = array("DROP", "SELECT", "UPDATE", "DELETE", "DELETE" , "UNION", "WHERE", "FROM");
      
        foreach($_REQUEST  as $value)
        {
          if(in_array(strtoupper($value), $badchars))
          {
          $logfile= 'log/log.txt'; //chmod 777
    $IP = $_SERVER['REMOTE_ADDR'];
    $logdetails= date("F j, Y, g:i a") . ': ' . '<a href=http://dnsstuff.com/tools/city.ch?ip='.$_SERVER['REMOTE_ADDR'].' target=_blank>'.$_SERVER['REMOTE_ADDR'].'</a>';
    $fp = fopen($logfile, "r+");
    fwrite($fp, $logdetails, strlen($logdetails));
    fclose($fp);
    
           header('Location:http://go-to-hell.com');
    
          }
          else
          {
            $check = preg_split("//", $value, -1, PREG_SPLIT_OFFSET_CAPTURE);
            foreach($check as $char)
            {
             if(in_array(strtoupper($value), $badchars))
              {
          $logfile= 'log/log.txt';
    $IP = $_SERVER['REMOTE_ADDR'];
    $logdetails= date("F j, Y, g:i a") . ': ' . '<a href=http://dnsstuff.com/tools/city.ch?ip='.$_SERVER['REMOTE_ADDR'].' target=_blank>'.$_SERVER['REMOTE_ADDR'].'</a>';
    $fp = fopen($logfile, "r+");
    fwrite($fp, $logdetails, strlen($logdetails));
    fclose($fp);
    
                header('Location:http://go-to-hell.com');
         }
        }
       }
      }
      } 
    
    and add in the begining of your script:
    PHP Code:
    check_injection(); 
    
    this is very good code buddy

    Leave a comment:


  • Anshul
    replied
    Code:
    if ($register_glob == 1){
    if (!ini_get('register_globals')) {
      $superglobals = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST, $_GET);
    
      if (isset($_SESSION)) {
        array_unshift($superglobals, $_SESSION);
      }
    
      foreach ($superglobals as $superglobal) {
        extract($superglobal, EXTR_SKIP);
      }
    }
    }
    usage
    Code:
    $register_glob = 1; //register_globals 1=on 0=off

    Leave a comment:


  • GumSlone
    replied
    Anti sql injection

    ANTI SQL INJECTION Function

    PHP Code:
    function check_injection()
      {
        $badchars = array("DROP", "SELECT", "UPDATE", "DELETE", "DELETE" , "UNION", "WHERE", "FROM");
      
        foreach($_REQUEST  as $value)
        {
          if(in_array(strtoupper($value), $badchars))
          {
          $logfile= 'log/log.txt'; //chmod 777
    $IP = $_SERVER['REMOTE_ADDR'];
    $logdetails= date("F j, Y, g:i a") . ': ' . '<a href=http://dnsstuff.com/tools/city.ch?ip='.$_SERVER['REMOTE_ADDR'].' target=_blank>'.$_SERVER['REMOTE_ADDR'].'</a>';
    $fp = fopen($logfile, "r+");
    fwrite($fp, $logdetails, strlen($logdetails));
    fclose($fp);
    
           header('Location:http://go-to-hell.com');
    
          }
          else
          {
            $check = preg_split("//", $value, -1, PREG_SPLIT_OFFSET_CAPTURE);
            foreach($check as $char)
            {
             if(in_array(strtoupper($char), $badchars))
              {
          $logfile= 'log/log.txt';
    $IP = $_SERVER['REMOTE_ADDR'];
    $logdetails= date("F j, Y, g:i a") . ': ' . '<a href=http://dnsstuff.com/tools/city.ch?ip='.$_SERVER['REMOTE_ADDR'].' target=_blank>'.$_SERVER['REMOTE_ADDR'].'</a>';
    $fp = fopen($logfile, "r+");
    fwrite($fp, $logdetails, strlen($logdetails));
    fclose($fp);
    
                header('Location:http://go-to-hell.com');
         }
        }
       }
      }
      } 
    
    and add in the begining of your script:
    PHP Code:
    check_injection(); 
    

    Leave a comment:


  • subzero
    replied
    It gets cookies

    it do all in one

    Works on my site


    The $_REQUEST Variable

    The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE.

    The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.

    Leave a comment:


  • subzero
    replied
    I got a better way for that code

    use $_REQUEST

    One line do all lmao

    PHP Code:
    if(isset($_REQUEST)){foreach($_REQUEST as $key=>$value){$_REQUEST[$key]=delhtml($value);}} 
    
    PHP Code:
    function delhtml($str) {
    return mysql_real_escape_string(htmlspecialchars($str));
    }
    
    if(isset($_GET)){foreach($_GET as $key=>$value){$_GET[$key]=delhtml($value);}}
    if(isset($_POST)){foreach($_POST as $key=>$value){$_POST[$key]=delhtml($value);}}
    if(isset($_SESSION)){foreach($_SESSION as $key=>$value){$_SESSION[$key]=delhtml($value);}}
    if(isset($_COOKIE)){foreach($_COOKIE as $key=>$value){$_COOKIE[$key]=delhtml($value);}} 
    

    Leave a comment:


  • Anshul
    replied
    PHP Code:
    function delhtml($str) 
    {
    return mysql_real_escape_string(htmlspecialchars($str));
    }
    
    if(isset($_GET)){foreach($_GET as $key=>$value){$_GET[$key]=delhtml($value);}}
    if(isset($_POST)){foreach($_POST as $key=>$value){$_POST[$key]=delhtml($value);}}
    if(isset($_SESSION)){foreach($_SESSION as $key=>$value){$_SESSION[$key]=delhtml($value);}}
    if(isset($_COOKIE)){foreach($_COOKIE as $key=>$value){$_COOKIE[$key]=delhtml($value);}} 
    

    Leave a comment:


  • Anshul
    replied
    gzcompress
    PHP Code:
    <?php
    
    function miscGzHandler($buf) {
        $zipRatio = 5;
        $zipDebug = 1;
    
        if(empty($buf) || !function_exists('gzcompress') || !isset($_SERVER['HTTP_ACCEPT_ENCODING'])) return $buf;
        $enc_ar = explode(',', $_SERVER['HTTP_ACCEPT_ENCODING']);
        $mayZip = false; $encoding = '';
        foreach($enc_ar as $enc) {
            $enc = trim($enc);
            if('gzip' == $enc || 'x-gzip' == $enc) {
                $mayZip = true;
                $encoding = $enc;
                break;
            }
        }
        if(!$mayZip) return $buf;
    
        $bufZiped = gzcompress($buf, $zipRatio);
        if($zipDebug) {
            $bufLen = strlen($buf);
            $bufZipedLen= strlen($bufZiped);
            $buf .= (2 == $zipDebug) ? "\n\n<!"."--\n" : "\n
    <pre style='width:15%; border:3px ridge; background-color:white; color:gray; font:xx-small Lucida Console, Courier New; padding:3px; margin:10px;'>\n";
            $buf .= "HTML content    : ".$bufLen." bytes\n";
            $buf .= "Compressed      : ".$bufZipedLen." bytes\n";
            $buf .= "GZip level      : ".$zipRatio."\n";
            $buf .= "Size difference : ".sprintf("%.1f%%", $bufZipedLen*100/$bufLen)."\n";
            $buf .= "Size ratio      : ".sprintf("%.1f", $bufLen/$bufZipedLen)." times\n";
            $buf .= (2 == $zipDebug) ? "--".">\n" : "</pre>\n";
            $bufZiped = gzcompress($buf, $zipRatio);
        }
        $bufZiped = pack('cccccccc',0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00)
            .substr($bufZiped, 0, -4)
            .pack('V',crc32($buf))
            .pack('V',strlen($buf));
        header('Content-encoding: '.$encoding);
        header('Content-length: '.strlen($bufZiped));
        return $bufZiped;
    }
    
    ob_start('miscGzHandler');
    
    
    ?>

    Leave a comment:


  • subzero
    replied
    Like

    deny from <USER IP>

    Not always need

    Code:
    <Files 404.shtml>
    order allow,deny
    allow from all
    </Files>

    Leave a comment:


  • rukiya
    replied
    That is the wildcard character which may be substituted for any of a defined subset of all possible characters

    This will ban 77.*.*.* the 3 subnos and the range is 77.0.0.0- 77.255.255.255 which will ban 256x256x256=16777216 ips. But 77.105.2.* will ban just a subno and the range is 77.105.2.0- 77.105.2.255 which will ban only 256 ips.

    Moreover it can be done with htaccess using <deny>

    Leave a comment:


  • metulj
    replied
    <div class='quotetop'>QUOTE (sweetangel @ Mar 7 2009, 10:33 AM) <{POST_SNAPBACK}></div>
    boss is good ban range like this :

    77.*.*.*[/b]
    it would be just
    Code:
    77.*
    and you do unerstand that will ban any one who&#39;s IP starts with 77 ?

    Leave a comment:


  • sweetangel
    replied
    boss is good ban range like this :

    77.*.*.*

    Leave a comment:


  • GumSlone
    replied
    ban ip range or ip

    PHP Code:
    $getip = $_SERVER["REMOTE_ADDR"];
    $banned_ip = array();
    
    $banned_ip[] = '194.9.94.*';
    $banned_ip[] = '77.105.2.*';
    
    foreach($banned_ip as $banned)
    {
    $blacked=str_replace('*', '', $banned);
    $len=strlen($blacked);
    if ($getip==$blacked || substr($getip, 0, $len)==$blacked)
    {
    $_banned_ip=true;
    }
    }
    
    if($_banned_ip==true){ 
    echo 'THIS IP IS BANNED!';
    exit; 
    } 
    

    Leave a comment:


  • something else
    replied
    nice function gum
    does HTTP_X_OPERAMINI_PHONE_UA
    work better than
    HTTP_X_OPERAMINI_PHONE ?
    also it still wont work against n95 hidden behind opera 8.65
    maybee an added option of
    $n95 = explode ("/", $_mob_browser);
    $opera = explode ("Opera", $_mob_browser);
    if(($n95[1]=="4.0 (compatible; MSIE 6.0; Symbian OS; Series 60)")&&($opera[1]==" 8.65 [en]"){
    $_browser[0] = "Nokia N95 (opera 8.65)";
    }
    or is there other s60v3 phones that show the same on opera?

    Leave a comment:

Working...
X