MySQLi显示为PHP代码

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (61)

我的问题是我无法登录,因为由于某种原因,它不让我,如果我有从数据库获取数据的代码它不工作(我有一个明确的连接,连接就好了)

    <?php
$steamauth['apikey'] = APIKEY; // Your Steam WebAPI-Key found at http://steamcommunity.com/dev/apikey
$steamauth['domainname'] = WEBSITE; // The main URL of your website displayed in the login page
$steamauth['logoutpage'] = WEBSITE; // Page to redirect to after a successfull logout (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
$steamauth['loginpage'] = WEBSITE; // Page to redirect to after a successfull login (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!

// System stuff
if (empty($steamauth['apikey'])) {die("<div style='display: block; width: 100%; background-color: red; text-align: center;'>SteamAuth:<br>Please supply an API-Key!<br>Find this in steamauth/SteamConfig.php, Find the '<b>\$steamauth['apikey']</b>' Array. </div>");}
if (empty($steamauth['domainname'])) {$steamauth['domainname'] = $_SERVER['SERVER_NAME'];}
if (empty($steamauth['logoutpage'])) {$steamauth['logoutpage'] = $_SERVER['PHP_SELF'];}
if (empty($steamauth['loginpage'])) {$steamauth['loginpage'] = $_SERVER['PHP_SELF'];}

$steamid=mysqli_connect("","","","");
$steamid->set_charset("utf8");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($steamid, "SELECT * FROM panel_admins");

if (!$result) {
    printf("Error: %s\n", mysqli_error($steamid));
    exit();
}

echo "";

while ($row = mysqli_fetch_array($result)) {

$allowed_ids = [
    '"' . $row['steamid'] . '"',
];

}

mysqli_close($steamid);
?>

但另一方面,如果我有这样的代码,我可以登录没有问题

<?php
$steamauth['apikey'] = APIKEY; // Your Steam WebAPI-Key found at http://steamcommunity.com/dev/apikey
$steamauth['domainname'] = WEBSITE; // The main URL of your website displayed in the login page
$steamauth['logoutpage'] = WEBSITE; // Page to redirect to after a successfull logout (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
$steamauth['loginpage'] = WEBSITE; // Page to redirect to after a successfull login (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!

// System stuff
if (empty($steamauth['apikey'])) {die("<div style='display: block; width: 100%; background-color: red; text-align: center;'>SteamAuth:<br>Please supply an API-Key!<br>Find this in steamauth/SteamConfig.php, Find the '<b>\$steamauth['apikey']</b>' Array. </div>");}
if (empty($steamauth['domainname'])) {$steamauth['domainname'] = $_SERVER['SERVER_NAME'];}
if (empty($steamauth['logoutpage'])) {$steamauth['logoutpage'] = $_SERVER['PHP_SELF'];}
if (empty($steamauth['loginpage'])) {$steamauth['loginpage'] = $_SERVER['PHP_SELF'];}

// allow only these ids
$allowed_ids = [
    'steamid64here',
];
?>

也许代码不好或什么的。我使用PHP 5.6!这个代码我想要什么?我想在蒸汽列中它将抓住steamid64然后放在那里。

提问于
用户回答回答于

$allowed_ids在每次传递中覆盖while循环的值 。

请尝试以下代码:

   $allowed_ids = array(); // initializing array
   while ($row = mysqli_fetch_array($result)) {
         $allowed_ids[] = $row['steamid'] ;// inserting elements into the array
   }

扫码关注云+社区

领取腾讯云代金券