-3 php mysql cookies minecraft
我试图使用的代码如下,我已经仔细检查了一切,并且它一直在说这个错误:致命错误:调用未定义的函数Votifier(),我不知道这里的问题是什么.这是我在这里问的最后一招,我已经谷歌搜索了2个小时..提前谢谢.
<?php
if (isset($_COOKIE['votfed']) && $_COOKIE['vofted'] == 'true') {
exit();
} else {
mysql_connect("", "", "")or die("cannot connect");
mysql_select_db("")or die("cannot select DB");
$result = mysql_query('SELECT * FROM servers WHERE id = "' . $_GET["server"] . '"');
while ($row = mysql_fetch_array($result)) {
$public_key = $row['votifier_key'];
$server_ip = $row['ip'];
$server_port = $row['votifier_port'];
$username = 'USERNAME';
}
$username = preg_replace("/[^A-Za-z0-9_]+/", '', $username);
if (Votifier($public_key, $server_ip, $server_port, $username)) {
echo 'Success!';
} else {
echo 'Error!';
}
ini_set('error_reporting', E_ALL);
function Votifier($public_key, $server_ip, $server_port, $username) {
$public_key = wordwrap($public_key, 65, "\n", true);
$public_key = <<<EOF
-----BEGIN PUBLIC KEY-----
$public_key
-----END PUBLIC KEY-----
EOF;
$address = $_SERVER['REMOTE_ADDR'];
$timestamp = time();
$string = "VOTE\MC-ServerLists.com\n$username\n$address\n$timeStamp\n";
$leftover = (256 - strlen($string)) / 2;
while ($leftover > 0) {
$string .= "\x0";
$leftover--;
}
openssl_public_encrypt($string, $crypted, $public_key);
$socket = fsockopen($server_ip, $server_port, $errno, $errstr, 3);
if ($socket) {
fwrite($socket, $crypted);
return true;
} else
return false;
}
mysql_connect("", "", "")or die("cannot connect");
mysql_select_db("")or die("cannot select DB");
mysql_query('insert into voters (server_id, ipaddress) VALUES ("' . $_GET["server"] . '", "' . $_SERVER['REMOTE_ADDR'] . '")');
}
Run Code Online (Sandbox Code Playgroud)
如果你正确地格式化了代码,你会发现函数是有条件定义的,因此,它的定义必须在你调用函数之前发生:
<?php
if (isset($_COOKIE['votfed']) && $_COOKIE['vofted'] == 'true') {
// ...
} else {
// ...
$username = preg_replace("/[^A-Za-z0-9_]+/", '', $username);
if (Votifier($public_key, $server_ip, $server_port, $username)) {
echo 'Success!';
} else {
echo 'Error!';
}
function Votifier($public_key, $server_ip, $server_port, $username)
{
// ...
}
// ...
}
?>
Run Code Online (Sandbox Code Playgroud)
基本上,您正在执行此代码:
<?php
if( false) {
} else {
if( foo()) {
echo 'Foo!';
}
function foo() {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
哪个应该显示foo()直到else执行后才定义,但是你foo()在else块的开头调用(在它定义之前).
你的函数应该在if语句之外,如下所示:
<?php
function Votifier($public_key, $server_ip, $server_port, $username)
{
// ...
}
if (isset($_COOKIE['votfed']) && $_COOKIE['vofted'] == 'true') {
// ...
} else {
// ...
$username = preg_replace("/[^A-Za-z0-9_]+/", '', $username);
if (Votifier($public_key, $server_ip, $server_port, $username)) {
echo 'Success!';
} else {
echo 'Error!';
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
或者,您可以将它放在else块的开头,但我不建议从可读性的角度来看它.
| 归档时间: |
|
| 查看次数: |
161 次 |
| 最近记录: |