/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Curl – Purchasing items with cookies.

Been working awhile on getting this completed with no luck
I have this script that is suppose to purchase items through cookies

[code=php]<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER[‘HTTP_USER_AGENT’]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_URL, “”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_USERAGENT, “MozillaXYZ/1.0″);

$data = array(
‘creator’ => ‘1’,
‘storeId’ => ‘123’,
‘items’ => ‘{id:123,species:stud,at:keepsake}’,
‘pType’ => ‘0’
);

$cookies = array(
//Purchase cookie Goes here
‘anx’ => ”,
‘anxs’ => ”,
‘JSESSIONID’ => ”,
‘dcDirtyCookie’ => ”,
‘user_num’ => ”,
‘user_nme’ => ”,
‘user_info’ => ”,
‘qinfo’ => ”
);

curl_setopt($ch, CURLOPT_COOKIE, $cookies);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$output = curl_exec($ch);
curl_close($ch);
die($output);
$xml = simplexml_load_string($output);
print_r($xml,1);
echo(“donen”);
echo($output);
?>
[/code]

But..
Instead of it purchasing items with the script provided above and me having my cookies in there it just echo’s them back out and onto the page, I would like for it to send the request to the requested url and purchase the item within the $data function.

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@ShiftauthorSep 16.2014 — bump..
Copy linkTweet thisAlerts:
@NogDogSep 16.2014 — According to the manual, the CURLOPT_COOKIE option expects a semi-colon-delimited list of name=value pairs, not a PHP array. You could parse your array with something like:
[code=php]
$cookieParts = array();
foreach($cookies as $name => $value) {
$cookieParts[] = $name.'='.urlencode($value);
}
curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookieParts));
[/code]
Copy linkTweet thisAlerts:
@ShiftauthorSep 16.2014 — Could you show me an example with my code that I already have?
Copy linkTweet thisAlerts:
@NogDogSep 16.2014 — Just replace the line you have setting CURLOPT_COOKIE with all the lines I suggested (and hope that (a) my analysis is correct, and (b) my typing is correct).
Copy linkTweet thisAlerts:
@ShiftauthorSep 16.2014 — Nice that worked, It no longer is pasting all of my cookies onto a page.. but it's still not processing the item when it should be hmm..
Copy linkTweet thisAlerts:
@ShiftauthorSep 16.2014 — Is there anyway that I can put an echo into this script to show like purchase has been complete.. I am a little afraid to even mess with the script now because i've been breaking it more and more all morning..
Copy linkTweet thisAlerts:
@NogDogSep 16.2014 — Add this with the other curl_setopt() calls:
[code=php]
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
[/code]

Then after the execute, $output should contain whatever the call returned from the remote site.
Copy linkTweet thisAlerts:
@ShiftauthorSep 16.2014 — Fixxed, Very nice thank you man.
×

Success!

Help @Shift spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...