Saturday, 15 September 2012

php - curl fails to correctly send headers -



php - curl fails to correctly send headers -

my initial project of checking whether apple id exists or not, have proceeded doing in php navigating apppleid.apple.com/account/ , pretending register business relationship fields blank except business relationship field, , if got error meant business relationship existed, otherwise if got other errors not "account exists" error homecoming false. have encountered few problems on way. first need preserve headers/cookies on way (which did) still not work, , apparently answers "1". code can found here : pastebin. please follow link , seek solve problem, need done. give thanks much whoever got time read post.

edit code:

<?php require("simplehtmldom_1_5/simple_html_dom.php"); $input = get_data('https://appleid.apple.com/account'); $html = new simple_html_dom(); $html->load($input); //echo $input; $table = array(); foreach($html->find('input') $inn) { $val = ""; seek { $val = $inn->getattribute('value'); } grab (exception $e) { $val = ""; } //echo $inn->getattribute('name') . $val . "\n"; if($inn->getattribute('name') != "" && $inn->getattribute('name') != "account.name") { $table[$inn->getattribute("name")] = $val; } if($inn->getattribute('name') == "account.name") { $table[$inn->getattribute("name")] = "naclo3samuel@gmail.com"; } } $nix = http_build_query($table); //set url, number of post vars, post info $ch = curl_init(); $hs = get_headers("https://appleid.apple.com/account", 0); $headers = $hs; curl_setopt($ch,curlopt_url, "https://appleid.apple.com/account/"); curl_setopt($ch,curlopt_post, count($nix)); curl_setopt($ch,curlopt_httpheader, $headers); curl_setopt($ch,curlopt_postfields, $nix); //execute post $result = curl_exec($ch); echo $result; //close connection curl_close($ch); /* gets info url */ function get_data($url) { $ch = curl_init(); $timeout = 5000; curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_connecttimeout, $timeout); $data = curl_exec($ch); curl_close($ch); homecoming $data; } ?>

one of problems right here: get_headers("https://appleid.apple.com/account", 0);

this homecoming like:

[0] => http/1.1 200 ok [1] => date: sat, 29 may 2004 12:28:13 gmt [2] => server: apache/1.3.27 (unix) (red-hat/linux) [3] => last-modified: wed, 08 jan 2003 23:11:55 gmt [4] => etag: "3f80f-1b6-3e1cb03b" [5] => accept-ranges: bytes [6] => content-length: 438 [7] => connection: close [8] => content-type: text/html

what curl supposed that? not in format acceptable curlopt_httpheader , neither headers server expect client request.

i suppose trying stablish cookie session. recommend without utilize of get_headers() or putting finger in headers @ all.

enable curl's cookie back upwards setting options curlopt_cookiejar , curlopt_cookiefile, create phone call https://appleid.apple.com/account initialize cookies, , rest.

example:

$cookies = tmpfile(); $curl = curl_init(); curl_setopt_array($curl, [ curlopt_url => "https://appleid.apple.com/account/", curlopt_cookiejar => $cookies, curlopt_cookiefile => $cookies, curlopt_returntransfer => true, curlopt_header => true ]); curl_exec(); curl_setopt_array($curl, [ curlopt_post => true, curlopt_postfields => $nix ]); $result = curl_exec($ch); $hsize = curl_getinfo($curl, curlinfo_header_size); $headers = explode("\r\n", substr($result, 0, $hsize)); $result = substr($result, $hsize);

php curl

No comments:

Post a Comment