以下实际上是我的php类的赋值。我在localhost上解决了这个问题。一切都在那里完美运行,但是当我将它上传到我的实时网站时,逻辑变得一团糟。这是典型的“猜猜游戏”计划。没有报告错误。
唯一的问题是,在实时服务器上时,用户可以输入任何内容 - 甚至是“1”,并显示其条目“太高” 。
这可能是我的网站(fatcow)php设置的问题吗?我认为发生的事情是以某种方式将某个会话变量显示为“零”,而不是rand(1,10)。为什么会这样?如何修复它以使其与我的localhost上的工作方式相同?
代码:
<?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');
?>
答案 0 :(得分:0)
(我会将我的评论添加为答案,因为它有助于解决问题。)
显然会话与Fat Cow托管开箱即用。一些链接见:
B中。 Bulpett。我建议您尝试使用register globals找到解决方案不,因为它已被弃用,并且将从PHP 5.4.0开始删除。