You are on page 1of 4

/**

* Copy File from HTTPS/SSL location


*
* @param string $FromLocation
* @param string $ToLocation
* @return boolean
*/
function copySecureFile($FromLocation,$ToLocation,$VerifyPeer=false,
$VerifyHost=true)
{
// Initialize CURL with providing full https URL of the file
location
$Channel = curl_init($FromLocation);
 
// Open file handle at the location you want to copy the file:
destination path at local drive
$File = fopen ($ToLocation, "w");
 
// Set CURL options
curl_setopt($Channel, CURLOPT_FILE, $File);
 
// We are not sending any headers
curl_setopt($Channel, CURLOPT_HEADER, 0);
 
// Disable PEER SSL Verification: If you are not running with
SSL or if you don't have valid SSL
curl_setopt($Channel, CURLOPT_SSL_VERIFYPEER, $VerifyPeer);
 
// Disable HOST (the site you are sending request to) SSL
Verification,
// if Host can have certificate which is nvalid / expired /
not signed by authorized CA.
curl_setopt($Channel, CURLOPT_SSL_VERIFYHOST, $VerifyHost);
 
// Execute CURL command
curl_exec($Channel);
 
// Close the CURL channel
curl_close($Channel);
 
// Close file handle
fclose($File);
 
// return true if file download is successfull
return file_exists($ToLocation);
}
/**
* This code don't work
* echo
file_get_contents("https://www.verisign.com/hp07/i/vlogo.gif");
**/
// Function Usage

if(copySecureFile("https://www.verisign.com/hp07/i/vlogo.gif","c:/verisign_log
o.gif"))
{
echo 'File transferred successfully.';
}
else
{
echo 'File transfer failed.';

http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/

curl is a command line tool for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS,
GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS,
TELNET and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based
upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file
transfer resume, proxy tunneling and a busload of other useful tricks.

http://blogs.digitss.com/php/curl-php/posting-or-uploading-files-using-curl-with-php/

cURL is very important tool for PHP programmers, we tends to do so many thing with using this tool.
Posting data, imitating a form post and lot more, it's usage is countless. Some time back I came across
situation where we have to post files to a 3rd party faxing service. I knew there are many possibilities
but I didn't wanted to get into sockets and file stream to get this done, just wanted to post FILE in
addition to rest of the post data.

// URL on which we have to post data


$url = "http://localhost/tutorials/post_action.php";
// Any other field you might want to catch
$post_data['name'] = "khan";
// File you want to upload/post
$post_data['file'] = "@c:/logs.log";
 
// Initialize cURL
$ch = curl_init();
// Set URL on which you want to post the Form and/or data
curl_setopt($ch, CURLOPT_URL, $url);
// Data+Files to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
// Pass TRUE or 1 if you want to wait for and catch the response against the
request made
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// For Debug mode; shows up any error encountered during the operation
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Execute the request
$response = curl_exec($ch);
 
// Just for debug: to see response
echo $response;

CURL help + secure passing of variables

Hi,

I am trying to use CURL to use GET to send data to a web page at a different url and then get the
browser to redirect to that new page.

I can get the page to echo the data I send it, however I cant get the page in the browser to redirect
to the new page. The url stays the same as the page using the curl function.

Is there anyway once you send the data as a GET, that you can redirect to that page using
CURL?

Here is the function I am using

Code:
function curlPOST($http, $postfields)
{
//echo "http: $http <br> PF: $postfields<br>";
// initialise Curl
$tbpost = curl_init();
// Set Curl Option: e.g URL
curl_setopt($tbpost, CURLOPT_URL, $http);
// Set Curl Option: Post style request = true
curl_setopt($tbpost, CURLOPT_HTTPGET, 1);
// Set Curl Option: Collect result from script
curl_setopt($tbpost, CURLOPT_RETURNTRANSFER, 1);
// Set Curl Option: Set timeout to 15 seconds
curl_setopt($tbpost, CURLOPT_TIMEOUT, 15);
// Set Curl Option: Post data
curl_setopt($tbpost, CURLOPT_POSTFIELDS, $postfields);
// Execute Request, and store result in $tb_post
$tbpost_result = curl_exec ($tbpost);
// Close Curl
curl_close ($tbpost);
// Show result to screen
echo $tbpost_result;
// return Result
return $tbpost_result;
}

I am trying to send data securely so the user can't see what variables I am passing to the page. Im
not sure if this is the best method.

Any suggestions on suitable methods if this is unsecure would be really helpful.

thanks

You might also like