哪裏是我在代碼中的錯誤?PHP - https:// POST-Request?
<?php
error_reporting(-1);
function PostRequest($url, $referer, $_data) {
// convert variables array to string:
$data = array();
while(list($n,$v) = each($_data)){
$data[] = "$n=$v";
}
$data = implode('&', $data);
// format --> test1=a&test2=b etc.
// parse the given URL
$url = parse_url($url);
// extract host and path:
$host = $url['host'];
$path = $url['path'];
// open a socket connection on port 80
$fp = fsockopen("ssl://".$host, 443);
// send the request headers:
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Referer: $referer\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ". strlen($data) ."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
$result = '';
$safe=0;
while(!feof($fp)&&$safe<1000) {
// receive the results of the request
$result .= fgets($fp, 128);
$safe++;
}
// close the socket connection:
fclose($fp);
// split the result header from the content
$result = explode("\r\n\r\n", $result, 2);
$header = isset($result[0]) ? $result[0] : '';
$content = isset($result[1]) ? $result[1] : '';
// return as array:
return array($header, $content);
}
/*
** The example:
*/
// submit these variables to the server:
$data = array(
'email'=>'testemail',
'pass'=>'testpass'
);
list($header, $content) = PostRequest("https://login.facebook.com/login.php", "http://facebook.com", $data);
// print the result of the whole request:
print $content;
?>
我想爲一些網站爲私人使用自動登錄腳本,此代碼應進行重定向到Facebook和全自動登錄到一個帳戶,但該代碼不工作,我的瀏覽器窗口仍然空白。
會很棒,如果有人,可以幫助我。我已經用CURL試過了,但我的測試網站Facebook說,Cookies沒有啓用。
使用捲曲。除非您瞭解成功完成HTTPS請求所需的私鑰和公鑰以及握手,否則不要插入HTTPS服務器。 –
你有沒有在你的服務器上配置ssl? –
我試過cURL,但它沒有工作,因爲有這些餅乾:( – Jannik