2013-04-20 88 views
1

以下實際上是我的PHP類的任務。我在我的本地主機上完成了它。一切都在那裏完美運行,但是當我將它上傳到我的現場網站時,邏輯就會全部搞砸了。這是典型的「猜猜遊戲」計劃。沒有錯誤報告。本地主機上完美的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'); 
?> 
+1

哪裏是你的活網站的鏈接? – underscore 2013-04-20 17:05:24

+0

你確定會話已保存嗎? – bwoebi 2013-04-20 17:14:43

+1

也許添加一個var_dump($ _ SESSION)語句到您的網站;並將其推到Live版本,以便查看並查看$ _SESSION的內容(如果有)以及它與本地主機上的內容有什麼不同。 – Dogoferis 2013-04-20 17:21:24

回答

0

(我將添加我的意見作爲一個答案,因爲它在解決問題的幫助。)

顯然會話不開箱與肥牛託管工作。有些鏈接查看:

B. Bulpett。我建議你試着找到一個解決方案而不是使用register globals,因爲它已被棄用,並將從PHP 5.4.0開始移除。

+0

謝謝!我與我的同事也使用FatCow分享這些信息。畢竟實際上並不需要register_globals。很高興知道它的待決棄權。 – 2013-04-20 21:49:48

相關問題