Can You Understand This Code !!

Discussion in 'PHP' started by mbanusick, Dec 9, 2010.

  1. #1
    <?php
    // Set execution time : 5 mins
    set_time_limit(300);
    error_reporting(0);
    // Should be same as defined in java constant file.
    // should be between 1-50
    $encKey =20;
    /*
    $myFile = "log.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    fclose($fh);
    $myFile = "log.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    */
    
    $line = file_get_contents("php://input");
    $encryptEnable = substr($line,0,1);
    $line =  substr($line,1);
    
    
    //fwrite($fh, ":INPUTTTTTTT:".$line.":INPUTTTTTTTTTTT:"); 
    
    if($encryptEnable=="Y"){
    $line = deccrypt_string($line);   }
    
    
    $hostport = substr($line,0,61);
    $bodyData = substr($line,61);
    $line ='';
    
    $host = substr($hostport,0,50);
    $port = substr($hostport,50,10);
    $issecure = substr($hostport,60,1);
    //fwrite($fh, $host); fwrite($fh, $port);  fwrite($fh, $issecure); 
    
    if($issecure=="Y"){
    $host = "ssl://".$host;
    }
    
    $fsok = fsockopen(trim($host) , intval(trim($port))); 
    if(FALSE == $fsok ) {echo "Target Host not Found/Down"; return ;}
    fwrite($fsok, $bodyData ); 
    $port ='';$host ='';$hostport= '';$bodyData='';
    
    while ($line = fread($fsok, 25000))
    {
    if($encryptEnable=="Y")
    echo encrypt_string($line);
    else
    echo $line;
    }
    
    fclose($fsok); 
    //fclose($fh); 
    
    
    ///////////////////////////////////////////////////////////////////////////////////////
    
    // Sample encrypt.Keeping the ouput size same.
    function encrypt_string($input)   
    {
    global $encKey;   
    $line="";
    for($i=0;$i<strlen($input);$i++){
    $line .= chr(ord($input[$i])+$encKey); 
    }
        return $line;   
    }   
      
    // Sample decrypt.Keeping the ouput size same.
    function deccrypt_string($input)   
    {   
    global $encKey; 
    $line="";
    for($i=0;$i<strlen($input);$i++){
    $line .= chr(ord($input[$i])-$encKey); 
    }
        return $line;   
    }   
    
    ?>
    
    PHP:
    Pls If you understand what is happening in this code I really need your help cos am new in PHP..
     
    mbanusick, Dec 9, 2010 IP
  2. badhim

    badhim Member

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #2
    This script:
    - gets string from the input stream
    - decrypts it if necessary
    - parses the host, port and data from this string
    - connects to the host: port and sends the data
    - receives the answer
    - crypts it if necessary
    - sends it back
     
    badhim, Dec 10, 2010 IP
  3. mbanusick

    mbanusick Greenhorn

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    @Badhim, thanks its what it does, actually a kind of proxy...my problem is that i would like to be able to display an additional info for everyone that uses the script, would like the info to appear at the bottom of the pages...pls can u help me with where to add the code n how to do it...
     
    mbanusick, Dec 11, 2010 IP