自动登录脚本

时间:2014-02-07 15:00:41

标签: php

如果我点击一个按钮,我正在尝试编写一个小网页,让我在spotify上登录。我写了一个简单的html网页,如果我点击一个按钮就连接到.php文件。 我正在使用的PHP脚本就是这个:

<?php /* $url = 'https://www.spotify.com/nl/login/?forward_url=%2Fnl%2Faccount%2Foverview%2F'; $username; $password; $html = file_get_contents($url);
$doc = new DOMDocument(); $doc->loadHTML($url);
$xpath = new DOMXpath($doc);
$nodes = $xpath->query("//a[@id = 'login-link-password']/@href");
foreach ($nodes as $entry) { echo "Found {$entry->previousSibling->previousSibling-   >nodeValue}," . " by {$entry->previousSibling->nodeValue}\n"; } */
$curl = curl_init('https://www.spotify.com/nl/login/?forward_url=%2Fnl%2Faccount%2Foverview%2F'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);   curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10'); $html = curl_exec($curl); curl_close($curl);
$dom = new DOMDocument(); @$dom->loadHTML($html);
$xpath = new DOMXPath($dom);

//$nodes = $xpath->query("//a[@id = 'login-link-password']/@href");

$unameval = 'test'; $uname = $xpath->query('//input[@type = "text"]/@name'); $pword =  $xpath->query('//input[@type = "password"]/@name'); $pwordval = '123456'; $inputnames = $xpath->query('//input[@type = "hidden"]/@name'); $inputvalues = $xpath->query('//input[@type = "hidden"]/@value');
$names = array(); $values = array();

/* foreach ($uname as $input) { print_r($input->childNodes->item(0)->nodeValue); } foreach ($pword as $input) { print_r($input->childNodes->item(0)->nodeValue); } foreach ($inputnames as $input) { print_r($input->childNodes->item(0)->nodeValue); } foreach ($unameval as $input) { print_r($input->childNodes->item(0)->nodeValue); } foreach ($pwordval as $input) { print_r($input->childNodes->item(0)->nodeValue); } foreach ($inputvalues as $input) { print_r($input->childNodes->item(0)->nodeValue); } */
$url = "https://www.spotify.com/nl/xhr/json/login.php"; $datapost = array('user_name' => 'test', 'password' => '123456', 'forward_url' => '/nl ', 'referrer' => '', 'utm-keywords' => ' 62b0eaea95adc2b222e58338c340bda8');

//redirect_post($url, $datapost, array('Location' => 'http://www.spotify.com/'));
//extract data from the post extract($_POST);
//set POST variables $url = 'https://www.spotify.com/nl/xhr/json/login.php'; $fields = array('user_name' => 'test', 'password' => '123456', 'forward_url' => '/nl/account/overview', 'referrer' => '', 'utm-keywords' => ' 62b0eaea95adc2b222e58338c340bda8');
//url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&');
//open connection $ch = curl_init();
//set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); //curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);
//execute post $result = curl_exec($ch);
//close connection curl_close($ch);
?>

但是,如果我填写我的凭证。我得到了回复:

{"msg":"","error":false,"redirect":"/nl/account/overview/"}

这个脚本有什么问题?我似乎无法弄明白......

0 个答案:

没有答案
相关问题