Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP to CURL

Status
Not open for further replies.

Cygnis

Technical User
Jul 3, 2012
1
US
I have this PHP scrip that acts as a proxy handler:


<?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);
echo "OOPs!....Try Unticking enable encryption in your IWP setting!"; }


$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;
}
?>


...and i want its equivalent in CURL, but since i dont know much about scripting i was wondering if any body can help me out...PLEASE!
 
curl is very straightforward
Code:
$ch = curl_init($url);
//then set some basic options 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //capture output
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //follow 303s
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //ignore https problems
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // time out 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //ignore common name problems

//do the request
$returnText = curl_exec($ch);

you can work it out from here, I'm sure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top