<?php
require '../Yahoo/src/Yahoo.php';
require '../vendor/autoload.php';

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;


$app = new \Slim\App();

$app->get('/categories/{id}', function (Request $request, Response $response, array $args) {

$api_key = "dj00aiZpPVhpTHlyZ3RMRmdaNiZzPWNvbnN1bWVyc2VjcmV0Jng9M2E-";
$api_secret = "8M0aZjLN9s1sijFGBEtDTE0yMw7CpN5cqLBrp0io";

$api = new \Yahoo\Api($api_key, $api_secret);

//echo '<pre>';
echo json_encode($api->get_category_tree( $args['id'] ));
//echo '</pre>';
	
});

$app->get('/products/{id_category}/{page_no}', function (Request $request, Response $response, array $args) {

$api_key = "dj00aiZpPVhpTHlyZ3RMRmdaNiZzPWNvbnN1bWVyc2VjcmV0Jng9M2E-";
$api_secret = "8M0aZjLN9s1sijFGBEtDTE0yMw7CpN5cqLBrp0io";

$api = new \Yahoo\Api($api_key, $api_secret);
echo json_encode( $api->get_auction_list(
	$args['id_category'], //Category ID
	$args['page_no'],		 //Page
	YAHOO_SORT_END_TIME,  //Sort default
	YAHOO_ORDER_ASC,  //Order default
	YAHOO_AUCTION_TYPE_ALL,  //Auction type all default
	100.00, //min auction price
	2000.00 //max auction price
) );
//echo '<pre>';
//echo json_encode($api->get_category_tree( $args['id_category'] ));
//echo '</pre>';
	
});

/*search product*/
$app->get('/search/{text}/{page_no}/{category}', function (Request $request, Response $response, array $args) {

$api_key = "dj00aiZpPVhpTHlyZ3RMRmdaNiZzPWNvbnN1bWVyc2VjcmV0Jng9M2E-";
$api_secret = "8M0aZjLN9s1sijFGBEtDTE0yMw7CpN5cqLBrp0io";

$api = new \Yahoo\Api($api_key, $api_secret);
echo json_encode($api->search($args['text'], YAHOO_SEARCH_TYPE_ALL, YAHOO_QUERY_TYPE_ALL, $args['page_no'], YAHOO_SORT_END_TIME, YAHOO_ORDER_ASC,$args['category']));
    
//echo '<pre>';
//echo json_encode($api->get_category_tree( $args['id_category'] ));
//echo '</pre>';
	
});




$app->get('/auction/{id}', function (Request $request, Response $response, array $args) {

$api_key = "dj00aiZpPVhpTHlyZ3RMRmdaNiZzPWNvbnN1bWVyc2VjcmV0Jng9M2E-";
$api_secret = "8M0aZjLN9s1sijFGBEtDTE0yMw7CpN5cqLBrp0io";

$api = new \Yahoo\Api($api_key, $api_secret);


echo json_encode($api->get_auction( $args['id'] ));

	
});

$app->get('/placebid', function (Request $request, Response $response, array $args) {
   /* 
    $id   = 'hbjun56371';
$pass = '@mshs2009#';
 
$cookie = realpath('cookie.txt');
 
// 好きなユーザーエージェントを設定
$user_agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko';
 
// ログインページを開く
$url = 'https://login.yahoo.co.jp/config/login?';
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
 
$html = curl_exec($ch);
curl_close($ch);
 
// 必要なポストデータを取得
preg_match_all(
            '/document\.getElementsByName\("\.albatross"\)\[0\]\.value = "(.*?)";/',
            $html,
            $albatross,
            PREG_SET_ORDER
        );
 
 
// ポストデータをセット
$POST_DATA  = array(
	'.ct'                 => '',
	'.display'            => '',
	'.done'               => 'http://www.yahoo.co.jp',
	'.keep'               => '',
	'.reg'                => 'https://account.edit.yahoo.co.jp/registration?src=www&done=http%3A%2F%2Fwww.yahoo.co.jp',
	'.src'                => 'www',
	'.suppreg_skip'       => '',
	'.yby'                => '',
	'auth_lv'             => '',
	'card_cushion_skip'   => '',
	'ckey'                => '',
	'nolink'              => '',
	'nonotice'            => '',
	'noreg'               => '',
	'referrer'            => '',
	't_cushion'           => '',
	'.albatross'          => $albatross[0][1],
	'.requiredPsCheckBox' => '',
	'.slogin'             => '',
	'.tries'              => '1',
	'ls_autocomp'         => '',
	'showpw_status'       => '',
	'login'               => $id,
	'passwd'              => $pass,
	'persistent'          => 'y'
);
 
 
// Yahoo!トップページにログイン
$url = 'https://login.yahoo.co.jp/config/login?.src=www&.done=http://www.yahoo.co.jp';
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('cookie.txt'));
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $POST_DATA);
 
echo $html = curl_exec($ch);
curl_close($ch);
 
    exit();*/
    $field=array(
        ".ct"=>"",
        ".display"=>"",
        ".done"=>" https://auctions.yahoo.co.jp/",
        ".keep"=>"",
        ".reg"=>"https://account.edit.yahoo.co.jp/registration?src=auc&done=https%3A%2F%2Fauctions.yahoo.co.jp%2F",
        ".src"=>"auc",
        ".suppreg_skip"=>"",
        ".yby"=>"",
        "auth_lv"=>"",
        "card_cushion_skip"=>"",
        "ckey"=>"",
        "nolink"=>"",
        "nonotice"=>"",
        "noreg"=>"",
        "referrer"=>"",
        "t_cushion"=>"",
        ".albatross"=>"dD1Xb2dDY0Imc2s9Z3FqTjhtMzVkeVJTZ0UzZE5ZVGVsVklvYXFJLQ==",
        ".requiredPsCheckBox"=>"",
        ".slogin"=>"",
        ".tries"=>"1",
        "ls_autocomp"=>"",
        "showpw_status"=>"",
        "u"=>"73esiupe0k2gm",
        "inactive_pw"=>"",
        "send_sms_counts"=>"1",
        "send_mail_counts"=>"1",
        "version"=>"",
        "auth_method"=>"pwd",
        "pwless_captchaid"=>"" ,
        "masked_dest"=>"",
        "bcrumb_id_check"=>"dD1Xb2dDY0Imc2s9bTBJU1c3OHB1dGRFa0pzZ2JmYVZtUTNDRWEwLQ==",
        "bcrumb_send_sms"=>"dD1Xb2dDY0Imc2s9Lm5OZVpMTGcucmpDcmRsM3pjODB4emtOMHZnLQ==",
        "bcrumb_send_mail"=>"dD1Xb2dDY0Imc2s9VE5PYnEzRDlqaXQzdUpsNEdVbDJ1TXdWOGVRLQ==",
        "user_name"=>"hbjun56371",
        "sms_push"=>"",
        "assertionInfo"=>"",
        "webauthn"=>"",
        "fido"=>"0",
        "auth_list"=>"pwd",
        "login"=>"hbjun56371",
        "passwd"=>"@mshs2009#",
        "code"=>"",
        "btnSubmit"=>"",
        ".persistent"=>"y",
        "yjbfp_items"=>"uaMozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36langen-USscreen_height768screen_width1366timezone_offset-330pluginsChrome PDF Plugin|Chrome PDF Viewer|Native Clientcanvas_imageiVBORw0KGgoAAAANSUhEUgAAABAAAAAWCAYAAADJqhx8AAAByUlEQVQ4T9WUv0vDUBSFv1AsaHUSxCylEmsddXGTgiJ2UhcFsY4OpaCIuLo4OQn+Dw61ILgFpJPoIDg4OLTWWlJKgqBYtFGMEnlP6s9apYrgnV6Sdw/3OznvKfywFNHvuhtuvTr/SGB9HXZ2YHUVGhtfgP8eYX/fxDCuGBnR8Ho9PE+wvOxSLCpvRnw99ubmFwi7uy7xOCQSCqEQ3NzA/Dz098PUFHzpwfm52OgSDucJBh26uzUWFjysrUGpZKLrVxSLGtPTZ1hWFQThq8AoFC7p6TFoaOjk4MDHysoD29snGEYLmYxKNGp+LpBOw9zcHUNDGdLpVsJhlcHBMrqex3ECUrCmQIVbVU85OnJYWtKw7TPpum1r7O15agsIDGFWPF5mYiLP4qKfw0MTv7+F42NVBqnmBEJAYExO3jM2lmNgoIlstkQkEiCV8n1fYHYWYjGTQsFCVX0yNMmk53sCAiGXc5mZsdnaytLb20Zfnyr/kKjhYat6Eis5ePJBwXGe3A+FAsRiTbJZhExkomqU318oIvMXF7dEIh1vPun6qXyuvP9wGq+v70gmM3LT+HgXzc1eubasskQSNTraSXu7T65/5zjXex+KvkcATSsyIKf0dAAAAABJRU5ErkJggg==",
        );
        
	$host = "https://login.yahoo.co.jp/config/login";

    $agent       = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36';
    $curlHeaders = array(
                "Accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
                "Accept-Encoding"=>"gzip, deflate, br",
                "Accept-Language"=>"en-US,en;q=0.9,hi;q=0.8",
                "Cache-Control"=>"max-age=0",
                "Connection"=>"keep-alive",
                "Content-Length"=>"1983",
                "Content-Type"=>"application/x-www-form-urlencoded",
                "Cookie"=>"TLS=v=1.2&r=1; F=a=Je9gDhUMvSR0sMPTcI08Dn9C.9AEDON1mspybRCJmtgrCHGUuG7LT.Fv.YI_6CTkNSSCQGw-&b=5P6h; YLS=v=2&p=1&n=1; B=cteocste0k1no&b=4&d=SNkLGqlpYF0t1pMr5rb_.H8L.Ou3K.jrfga5trmi&s=vo&i=cO6fexArEd96dbS44.ZZ",
                "Host"=>"login.yahoo.co.jp",
                "Origin"=>"https://login.yahoo.co.jp",
                "Referer"=>"https://login.yahoo.co.jp/config/login?.src=auc&.done=https%3A%2F%2Fauctions.yahoo.co.jp%2F",
                "Upgrade-Insecure-Requests"=>"1",
                "User-Agent"=>"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
                );
    $ch          = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeaders);
    curl_setopt($ch, CURLOPT_HEADER, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // following redirects or not
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $field);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('cookie.txt'));
	curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('cookie.txt'));
    curl_setopt($ch, CURLOPT_URL, $host);
    $result      = curl_exec($ch);
    var_dump($result);
	//$result = curl_exec($ch);
	
	curl_close($ch);
    
    
    exit();
set_time_limit(0);

$php_userid = 'hbjun56371';
$php_password ='@mshs2009#';


$cookie_file_path = "cookie.txt"; // Please set your Cookie File path
$fp = fopen($cookie_file_path,'w');
//$fp = fopen($cookie_file_path,'wb');
fclose($fp);
$agent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36";
//$reffer = "http://ichart.finance.yahoo.com/table.csv?s=DDD&a=11&b=4&c=2013&d=11&e=6&f=2013";
$reffer = "https://login.yahoo.co.jp/config/login?.lg=jp&.intl=jp&.src=auc&.done=http://auctions.yahoo.co.jp/jp";
/*
// log out.
$LOGINURL = "http://us.ard.yahoo.com/SIG=12hoqklmn/M=289534.5473431.6553392.5333790/D=mail/S=150500014:HEADR/Y=YAHOO/EXP=1135053978/A=2378664/R=4/SIG=133erplvs/*http://login.yahoo.co.jp/config/login?logout=1&.done=http://ichart.finance.yahoo.com/table.csv?s=DDD&a=11&b=4&c=2013&d=11&e=6&f=2013";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
//curl_setopt($ch, CURLOPT_PROXY, '206.221.182.74:2083');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
echo curl_error($ch);
curl_close ($ch);
sleep(10);
*/
//1. Get first login page to parse hash_u,hash_challenge https://auctions.yahooapis.jp/AuctionWebService/V

$LOGINURL = "https://login.yahoo.co.jp/config/login";
//$LOGINURL='https://auctions.yahooapis.jp/AuctionWebService/V';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
//curl_setopt($ch, CURLOPT_PROXY, '206.221.182.74:2083');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$loginpage_html = curl_exec ($ch);
$bid_inputs = get_inputs($loginpage_html);
$bid_inputs['auth_method']='pwd';
$bid_inputs['user_name']='amit saini';
$bid_inputs['fido']=0;
$bis_inputs['auth_list']="pwd";
$bis_inputs['login']="hbjun56371";
$bid_inputs['passwd']="@mshs2009#";
//$bid_inputs['captchaForm']="0";
//$bid_inputs['validate']="validate";
//$bid_inputs['.sectry']="0";
print_r($bid_inputs);
//echo $loginpage_html;
echo curl_error($ch);
curl_close ($ch);

preg_match_all("/name=\".u\" value=\"(.*?)\"/", $loginpage_html, $arr_hash_u);
preg_match_all("/name=\".challenge\" value=\"(.*?)\"/", $loginpage_html, $arr_hash_challenge);

//$hash_u = $arr_hash_u[1][0];
//$hash_challenge = $arr_hash_challenge[1][0];


//.tries=1&.src=auc&.last=http%3A%2F%2Flogin.yahoo.co.jp%2Fconfig%2Fedit_auc&promo=&.intl=jp&.bypass=&.partner=&.u=cq4ce2ov02mdi&.v=0&.fUpdate=Y&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fuser.auctions.yahoo.co.jp%2Fjp%2Fshow%2Fmystatus&login=********&passwd=***********
// 2- Post Login Data to Page https://login.yahoo.com/config/login?
sleep(5);
$LOGINURL = "https://login.yahoo.co.jp/config/login";

$POSTFIELDS = '.ct=^&.display=^&.done=https^%^3A^%^2F^%^2Fauctions.yahoo.co.jp^%^2F^&.keep=^&.reg=https^%^3A^%^2F^%^2Faccount.edit.yahoo.co.jp^%^2Fregistration^%^3Fsrc^%^3Dauc^%^26done^%^3Dhttps^%^253A^%^252F^%^252Fauctions.yahoo.co.jp^%^252F^%^26sr_required^%^3Dbirthday^%^2Bgender^%^2Bpostcode^%^2Bdeliver^&.src=auc^&.suppreg_skip=^&.yby=^&auth_lv=pw^&card_cushion_skip=^&ckey=^&nolink=^&nonotice=^&noreg=^&referrer=^&t_cushion=^&.albatross=dD1NdlYzYkImc2s9Ti5WMmtXYnVUek5pUmFYcXhweENyYWN0cjFRLQ^%^3D^%^3D^&.requiredPsCheckBox=^&.slogin=^&.tries=1^&ls_autocomp=^&showpw_status=^&u=cfd9pl5dtqmuc^&inactive_pw=^&version=^&auth_method=pwd^&pwless_captchaid=^&masked_dest=^&bcrumb_id_check=dD1NdlYzYkImc2s9cGJQeFlCNGdzQ1VWN2NKZkNqSkcyYnZYTUNFLQ^%^3D^%^3D^&bcrumb_send_sms=dD1NdlYzYkImc2s9VGFhLllHVjFpd01ZX1ViOHFEQVdPekg1dzZjLQ^%^3D^%^3D^&bcrumb_send_mail=dD1NdlYzYkImc2s9c012TFNJVkVLZU92OFJJRzdjRW9qMW84WGxnLQ^%^3D^%^3D^&user_name=lepinoux78^&sms_push=^&assertionInfo=^&webauthn=^&fido=0^&auth_list=pwd^&login=lepinoux78^&passwd=lafayette^&code=^&btnSubmit=^&.persistent=y^&yjbfp_items=ua^%^02Mozilla^%^2F5.0+^%^28Windows+NT+6.3^%^3B+Win64^%^3B+x64^%^29+AppleWebKit^%^2F537.36+^%^28KHTML^%^2C+like+Gecko^%^29+Chrome^%^2F70.0.3538.77+Safari^%^2F537.36^%^01lang^%^02en-US^%^01screen_height^%^02768^%^01screen_width^%^021366^%^01timezone_offset^%^02-330^%^01plugins^%^02Chrome+PDF+Plugin^%^7CChrome+PDF+Viewer^%^7CNative+Client^%^01canvas_image^%^02iVBORw0KGgoAAAANSUhEUgAAABAAAAAWCAYAAADJqhx8AAAByUlEQVQ4T9WUv0vDUBSFv1AsaHUSxCylEmsddXGTgiJ2UhcFsY4OpaCIuLo4OQn^%^2BDw61ILgFpJPoIDg4OLTWWlJKgqBYtFGMEnlP6s9apYrgnV6Sdw^%^2F3OznvKfywFNHvuhtuvTr^%^2FSGB9HXZ2YHUVGhtfgP8eYX^%^2FfxDCuGBnR8Ho9PE^%^2BwvOxSLCpvRnw99ubmFwi7uy7xOCQSCqEQ3NzA^%^2FDz098PUFHzpwfm52OgSDucJBh26uzUWFjysrUGpZKLrVxSLGtPTZ1hWFQThq8AoFC7p6TFoaOjk4MDHysoD29snGEYLmYxKNGp^%^2BLpBOw9zcHUNDGdLpVsJhlcHBMrqex3ECUrCmQIVbVU85OnJYWtKw7TPpum1r7O15agsIDGFWPF5mYiLP4qKfw0MTv7^%^2BF42NVBqnmBEJAYExO3jM2lmNgoIlstkQkEiCV8n1fYHYWYjGTQsFCVX0yNMmk53sCAiGXc5mZsdnaytLb20Zfnyr^%^2FkKjhYat6Eis5ePJBwXGe3A^%^2BFAsRiTbJZhExkomqU318oIvMXF7dEIh1vPun6qXyuvP9wGq^%^2Bv70gmM3LT^%^2BHgXzc1eubasskQSNTraSXu7T65^%^2F5zjXex^%^2BKvkcATSsyIKf0dAAAAABJRU5ErkJggg^%^3D^%^3D';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
//curl_setopt($ch, CURLOPT_PROXY, '206.221.182.74:2083');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($bid_inputs));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);
//echo curl_error($ch);
//fclose($fp);
print_r($result);

});

$app->post('/getauctions', function (Request $request, Response $response, array $args) {

$api_key = "dj00aiZpPVhpTHlyZ3RMRmdaNiZzPWNvbnN1bWVyc2VjcmV0Jng9M2E-";
$api_secret = "8M0aZjLN9s1sijFGBEtDTE0yMw7CpN5cqLBrp0io";

$api = new \Yahoo\Api($api_key, $api_secret);

foreach($request->getParsedBody() as $key => $value) {
	$post_array[$key] = $value;
}

echo '<pre>';
print_r($api->get_auction_list( $post_array['catid'], $page = (isset($post_array['page']) ? $post_array['page'] : '1'), $sort = (isset($post_array['sort']) ? $post_array['sort'] : 'YAHOO_SORT_END_TIME') ));
echo '</pre>';
	
});

$app->run();

function go_to_page($url, $headers = null) {
    
	$ch = curl_init();
	
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('cookie.txt'));
	curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('cookie.txt'));
	
	$result = curl_exec($ch);
	
	curl_close($ch);

	return $result;

}

function post_to_page($url, $fields, $headers = null) {
 
	$ch = curl_init();
	
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);	
	curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
	curl_setopt($ch, CURLOPT_COOKIEFILE,"cookie.txt");
	
	$result = curl_exec($ch);
	echo curl_error($ch);
	curl_close($ch);

	return $result;

}

function get_inputs($response) {
		
	$content = str_get_html($response);
	
	foreach($content->find('input') as $input) {
		$inputs[$input->name] = $input->value;
	}
	
	return $inputs;
}
	
?>