4
我想要做的是在我的網站上添加對Votifier插件的支持。使用fsockopen連接到服務器 - 連接被拒絕
我已經轉發了Minecraft服務器的正確端口,進行測試並確認它們已打開。還使用Minestatus來確認Votifier插件工作正常。
但是,當我嘗試使用我發現連接到服務器的PHP腳本時,我所得到的只是一個連接被拒絕。
<?php
error_reporting(E_ALL);
// Details of the vote.
$str = "VOTE\n" .
"TopHCSMP\n" .
"SlickTheNick666\n" .
"50.98.149.40\n" .
time()."\n";
// Fill in empty space to make the encrypted block 256 bytes.
$leftover = (256 - strlen($str))/2;
while ($leftover > 0) {
$str .= "\x0";
$leftover--;
}
// The public key, this is an example.
$key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkFywgrx2fPXL/CPS1Gi5/a7zoTfWV9fqrhsJMzPqqC0CnLBBkg8VUiwnBVsMvhJrUT1mLvyHx5H9dobTVlE+aoxcsDRa1Yc9OAUKHspxrPswRW6/Yn85YAghOSBZfgPoXD3Q0Ng5jkJUoBUHOBtFHDUeAHi5av36iJ8dTQTSaOyAXKGdB88TOzre5cpnj5oDi/JSJ0bCJx7cgcBAO1TvOVuFMTXhygDyEVh6 o2nn8+qdDlEPXf+m+dxdkH3zWkkWjY4OittIpaHj2n8ihgPqwMPZFH1CXkoTjoSh4Fo7KtUAaAa4gt5w/thauozG25G 1s2XSigNgCDDvg4S8awmtewIDAQAB";
$key = wordwrap($key, 65, "\n", true);
$key = <<<EOF
-----BEGIN PUBLIC KEY-----
$key
-----END PUBLIC KEY-----
EOF;
// Encrypt the string.
openssl_public_encrypt($str, $encrypted, $key);
// Establish a connection to Votifier.
$socket = fsockopen("50.98.149.40", "8192", $errno, $errstr, 2);
if (!$socket) {
die("Failed to connect to Votifier.");
}
// Send the contents of the encrypted block to Votifier.
fwrite($socket, $encrypted);
?>
似乎是Votifier正在斷開連接,可能是因爲加密不正確?
如果您使用的是共享主機,則可能會阻止出站端口8142。例如,GoDaddy共享主機只能在443和80上使用fsockopen。 – Drakes 2016-07-20 12:33:38