下面实际上是我的php类的赋值。我在我的本地主机上算出来的。一切都运行得很完美,但当我把它上传到我的现场时,逻辑就全搞砸了。这是一个典型的"猜谜游戏"节目。没有错误报告。
唯一的问题是,当在实时服务器上时,用户可以输入任何 -甚至"1",这表明他们的条目"太高"。这可能是我的网站的(fatcow) php设置的问题吗?我认为正在发生的事情是,出于某种原因,它将我的会话变量显示为"零",而不是rand(1,10)数字。为什么会发生这种情况?我如何修复它,使它的工作原理与它在我的本地主机上一样?
代码:
<?php
session_start();
error_reporting (E_ALL | E_STRICT);
$pageTitle = "Guessing Game";
include('includes/header.inc.php');
if (isset($_POST['finish']))
{
unset($_SESSION);
$_SESSION = array();
session_destroy();
die ('<h2>Congratulations</h2>
<p>Your session has been reset.<br />
Click <a href="guessingGame.php">HERE</a> to play again!</p>');
}
elseif (isset($_POST['guess']))
{
$_SESSION['count'] = $_SESSION['count'] + 1;
$guess = $_POST['guess'];
if (!ctype_digit($guess) || $guess <= 0 || $guess > 10 )
{
echo'<p span class="italic">SORRY, that entry is invalid</span></p>';
}
else
{
if ($guess == $_SESSION['num'])
{
die ('<h1>Hooray!</h1>
<h2>You got it correct<br />
And it only took you ' . $_SESSION['count'] . ' tries!</h2>
<p>Click the button to finish:</p>
<form action="guessingGame.php" method="post">
<input type="submit" name="submit" value="Finished" />
<input type="hidden" name="finish" value="true" />
</form></p>');
}
elseif ($guess < $_SESSION['num'])
{
echo '<h2>Sorry, that is incorrect.</h2>
<p>Your guess is too LOW</p>';
}
else
{
echo '<h2>Sorry, that is incorrect.</h2>
<p>Your guess is too HIGH</p>';
}
}
}
else
{
$_SESSION['num'] = rand(1,10);
$_SESSION['count'] = 0;
}
?>
<h1>Please guess a number between 1 and 10</h1>
<p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<input type="text" name="guess" size="2" />
<input type="submit" name="submit" value="Submit" />
</form>
</p>
<?php
include('includes/footer.inc.php');
?>
(我将添加我的评论作为答案,因为它有助于解决问题。)
显然会话不能在Fat Cow主机上开箱工作。一些链接:
- http://theedgeofall.com/journeys/2010/04/21/php-ini-issues-fat-cow-hosting/
- http://www.fatcow.com/knowledgebase/beta/article.bml?ArticleID=1290
- http://www.fatcow.com/knowledgebase/read_article.bml?kbid=7090
B。Bulpett。我建议您尝试找到一个解决方案而不是使用全局寄存器,因为它已被弃用,并将从PHP 5.4.0起删除。