我有一个子文件夹,其中存在老虎机操作所需的所有文件。包括具有php和js功能的文件夹。在实践中,即使路径正确,我也无法加载页面外部的功能,就像无法连接到资源一样。要明确的是,我有插槽文件夹所在的根文件夹。在slot文件夹内有特定文件夹中的子文件夹,其中包含带有php和js函数以及javascripts的文件。仅在加载时,索引才会加载这些文件。如何改善代码以解决问题?
<?php
session_start();
require_once ('slots/db.php');
require_once ('slots/users.php');
require_once ('slots/slotsmachine.php');
$userID = Users::LoggedUserID();
if (!$userID) {
header("location: ../index.php");
// Decide how to deal with non-logged in people
//throw new Exception "Not logged in";
}
$userData = Users::GetUserData($userID);
$windowID = rand(); // WindowID is used to identify each Window, in case the user opens more than one at a time, and spins in all of them. Sent straight up to the server.
$machineName = 'default';
?>
<!DOCTYPE html>
<html>
<head>
<title>Slot Machine</title>
<link type="text/css" rel="stylesheet" href="css/slots.css" />
<link type="text/css" rel="stylesheet" href="css/template5.css" />
</head>
<body>
<div id="PageContainer">
<div id="PageContainerInner"> <!-- Just to be able to set the "won!" extra background -->
<div id="prizes_list">
<?php
$prizes = SlotsMachine::ListPrizesForRendering($machineName);
foreach ($prizes as $prize) { ?>
<div id="trPrize_<?php echo $prize['id']; ?>" class="trPrize">
<div class="tdReels">
<div class="reel1 reelIcon <?php echo $prize['image1']['image_name']; ?>"></div>
<div class="reel2 reelIcon <?php echo $prize['image2']['image_name']; ?>"></div>
<div class="reel3 reelIcon <?php echo $prize['image3']['image_name']; ?>"></div>
<div class="clearer"></div>
</div>
<span class="tdPayout" data-basePayout="<?php echo $prize['payout_winnings']; ?>"><?php echo (float) $prize['payout_winnings']; ?></span>
<div class="clearer"></div>
</div>
<?php } ?>
</div>
<div id="slotMachineContainer">
<div id="ReelContainer">
<div id="reel1" class="reel"></div>
<div id="reel2" class="reel"></div>
<div id="reel3" class="reel"></div>
<div id="reelOverlay"></div>
</div>
<div id="loggedOutMessage" style="display: none;"><span class="large">Sorry, you have been logged off.</span><br />
<b>No bids</b> have been deducted from this spin, because you're not logged in anymore.
Please <a href="/login">login</a> and try again.
</div>
<div id="failedRequestMessage" style="display: none;"><span class="large">Sorry, we're unable to display your spin because your connection to our server was lost. </span><br />
Rest assured that your spin was not wasted.
Please check your connection and <a href="#" onclick="window.location.reload();">refresh</a> to try again.
</div>
<div id="betContainer">
<span id="lastWin"></span>
<span id="credits"><?php echo (float) $userData['credits']; ?></span>
<span id="bet"><?php echo SlotsMachine::MinBet($machineName); ?></span>
<span id="dayWinnings"><?php echo (float) $userData['day_winnings']; ?></span>
<span id="lifetimeWinnings"><?php echo (float) $userData['lifetime_winnings']; ?></span>
<div id="betSpinUp"></div>
<div id="betSpinDown"></div>
</div>
<div id="spinButton"></div>
</div>
<div id="soundOffButton"></div>
<script type="text/javascript">
var machineName = '<?php echo $machineName; ?>';
var minBet = <?php echo SlotsMachine::MinBet($machineName); ?>;
var maxBet = <?php echo SlotsMachine::MaxBet($machineName); ?>;
var numIconsPerReel = <?php echo SlotsMachine::IconsPerReel($machineName); ?>;
var windowID = <?php echo $windowID; ?>;
</script>
<script type="text/javascript" src="slot/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="slot/js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="slot/js/soundmanager2.js"></script>
<script type="text/javascript" src="slot/js/slots.js"></script>
</div>
</div>
</body>
</html>
如果我在没有子文件夹设置的情况下进入根文件夹,则会产生其他错误
<?php
class Users {
// This function gets called *a lot*, so it must be very quick to run. Cache stuff if necessary.
public static function LoggedUserID() {
return isset($_SESSION['ID']) ? $_SESSION['ID'] : null;
}
// Must return credits, day_winnings and lifetine_winnings
// Day_winnings may be implemented in multiple different ways. The server doesn't implement them as-is
public static function GetUserData($ID) {
return DB::SingleRow("SELECT credits, AS day_winnings, lifetime_winnings FROM 5fa_users WHERE id = " . DB::DQ($ID) . ";");
}
public static function IncrementSlotMachineSpins($ID) {
DB::Execute("UPDATE 5fa_users SET spins = spins + 1 WHERE id = " . DB::DQ($ID) . ";");
}
public static function DeductCredits($ID, $bet) {
DB::Execute("UPDATE 5fa_users SET credits = credits - " . DB::DQ($bet) . " WHERE id = " . DB::DQ($ID) . ";");
// If you have any sort of audit for your user's credits, you want to log into that
}
public static function IncreaseCredits($ID, $payout) {
DB::Execute("UPDATE 5fa_users SET credits = credits + " . DB::DQ($payout) . " WHERE id = " . DB::DQ($ID) . ";");
// If you have any sort of audit for your user's credits, you want to log into that
}
public static function IncreaseWinnings($ID, $payout) {
DB::Execute("UPDATE 5fa_users SET lifetime_winnings = lifetime_winnings + " . DB::DQ($payout) . " WHERE id = " . DB::DQ($ID) . ";");
// If you have any sort of audit for your user's credits, you want to log into that
// If you keep track of day_winnings, you probably want to update them here too
}
public static function HasEnoughCredits($ID, $bet){
$userData = self::GetUserData($ID);
return ($userData['credits'] >= $bet);
}
}
答案 0 :(得分:0)
像这样更改这些文件,因为要从index.php
访问这些文件,因此首先必须先依次转到slot
和slots
,然后才能访问诸如{{1} }
slotsmachine.php