how to maintaining session when using more than one curl script - session

i used curl to login a website. the code is:
<?php
$cookie_file = tempnam('./temp','cookie');
$login_url = 'http://bbs.xxxx.com/login.php';
$post_fields = 'cktime=31536000&step=2&pwuser=xx&pwpwd=111111';
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
$url='http://bbs.xxx.com/userpay.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
preg_match("/<li> (.*)<\/li>/",$contents,$arr);
echo $arr[1];
curl_close($ch);
?>
it works fine,but the problem is that when i make it into two files(a.php,b.php).it does not work.
i make a.php like:
<?php
$cookie_file = tempnam('./temp','cookie');
$login_url = 'http://bbs.xxxx.com/login.php';
$post_fields = 'cktime=31536000&step=2&pwuser=xx&pwpwd=111111';
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
?>
and b.php like:
<?php
$cookie_file = tempnam('./temp','cookie');
$url='http://bbs.xxx.com/userpay.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
preg_match("/<li> (.*)<\/li>/",$contents,$arr);
echo $arr[1];
curl_close($ch);
?>
i first visit a.php,then visit b.php. it dose not work!!!!
can any one help me?
it that different curl scripts can not share session???

In the first CODE you use one $cookie_file for two requests.
You should use same $cookie_file in a.php and b.php.
But you create two different $cookie_file with
$cookie_file = tempnam('./temp','cookie');
You create one in a.php.
Then you create another different one in b.php.

Related

How to determine IP and Port in random proxy script for curl?

I have a random IP script for curl but I don't know how to use port for same random script:
function curl_get($kix)
{
$ips = array(
'85.10.230.132',
'88.198.242.9',
'88.198.242.10',
'88.198.242.11',
'88.198.242.12',
'88.198.242.13',
'88.198.242.14',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $kix);
#curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_INTERFACE, $ips[rand(0, count($ips)-1)]);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
You can see here I have mentioned the IP, but I don't know how to mention port for those IPs.
Thanks in advance.
These are interfaces. Interfaces can be by name or ip (i.e. eth0). You don't specify a port.

Adding a note for a subscriber using Mailchimp API

I am having trouble adding a note to a subscriber using Mailchimp's API. Here's what I have:
$email = 'some#email.com';
$list = '123456';
$note = 'This is an example of a note.';
$apiKey = 'MY-API-KEY';
$memberId = md5(strtolower($email));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/lists/'.$list.'/members/'.$memberId.'/notes';
$json['note'] = $note;
$json = json_encode($json);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
return true;
} else {
return false;
}
Any ideas why these notes would not be saved? I've made sure the API key, the list ID and the email address are all correct.
The documentation page is here: https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/notes/

How to upload image from one domain to another?

I have two domain one is stgportal and another is stg.I want to upload image from stgportal to stg.My code is given below
move_uploaded_file($_FILES['ThumbnailImage']['tmp_name'],"http://stg.eminencesystem.com/assets/images/th/".$thimg)
show the error: failed to open stream: HTTP wrapper does not support writeable connections
how can i resolve this issue?
You can use CURL to send file to another server securely like this
At stgportal side
function sendImageToServer($path = "", $file = null)
{
$post_url = "http://stg.eminencesystem.com/post_file";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $post_url);
//most importent curl assues #filed as file field
$post_array = array(
"folder_name" => $path
);
if ((version_compare(PHP_VERSION, '5.5') >= 0)) {
$post_array['file'] = new CURLFile($file);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, TRUE);
} else {
$post_array['file'] = "#" . $file;
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
$response = curl_exec($ch);
return $response;
}
At stg side
$ImagePath = "/var/www/html/assets/";
$files = $_FILES;
$folder_name = utf8_decode($_POST['folder_name']);
$savepath = $ImagePath . $folder_name . $files['name'];
copy($file['tmp_name'], $savepath);
echo 1;
exit;

Google+ share count error

I'm having a problem finding the share count of a website in google+.I've done the facebook, tweeter etc but i cant figure out how to do it in google+. I have searched this solution but only it returns 0.
function get_plusones($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"#viewer","groupId":"#self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$curl_results = curl_exec ($curl);
curl_close ($curl);
$json = json_decode($curl_results, true);
return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
}
What have i done wrong?Any solution?
Found the solution didn't put www in front of the url.

500 Internal Server Error on Payza IPN Handler

I am migrating an app from PayPal to Payza (formerly AlertPay). When I run the code directly from the browser to test the token handling it shows up in the logs and I get a proper response: token=47TXhMVgdPrmV3n5aauIZ5CC0MrytYXWjID81pjVnQsEhkSUklPXT3clXZ4SFUFOL5WqepRUpBz5SKomoyPuDw==& INVALID TOKEN. When I run the full IPN response directly in the browser I get a fail but no visible errors.
But when I generate a transaction or resend an IPN from Payza it is not showing up in the log and I am getting a 500 Internal Server Error. I have turned on allow Query Strings in the CI config file.
class PayzaIPN {
function validate_ipn($payzaIPN ='',$logId = null) {
define("IPN_V2_HANDLER", "https://secure.payza.com/ipn2.ashx");
define("TOKEN_IDENTIFIER", "token=");
$_POST['token'] = '';
$token = urlencode($_POST['token']);
$token = TOKEN_IDENTIFIER.$payzaIPN;
$response = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, IPN_V2_HANDLER);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
if(strlen($response) > 0)

Resources