2008-10-20 62 views
0

這是我用來驗證用戶的精簡版本,它對我的​​PHP v5.0.2/MySQL 4.0.21服務器,但在我的PHP v5.1.6/MySQL v5.0.45服務器上失敗。PHP/MySQL登錄在一臺服務器上運行(PHP 5.0.2),但不能在另一臺服務器上運行(PHP 5.1.6)

在下面的代碼中,我應該知道任何可能不被新版本的PHP & MySQL支持的東西嗎?全局變量已啓用。

<?php 
    if(!isset($HTTP_POST_VARS['username'])&&!isset($HTTP_POST_VARS['password'])) 
    { 
    //Visitor needs to enter a name and password 
?> 
    <h1>Please Log In</h1> 
    This page is secret. 
    <form method="post" action="<?php echo $PHP_SELF;?>"> 
    <table border="1"> 
    <tr> 
     <th> Username </th> 
     <td> <input type="text" name="username"> </td> 
    </tr> 
    <tr> 
     <th> Password </th> 
     <td> <input type="password" name="password"> </td> 
    </tr> 
    <tr> 
     <td colspan="2" align="center"> 
     <input type="submit" value="Log In"> 
     </td> 
    </tr> 
    </table> 
    </form> 
<?php 
    } 
    else 
    { 
    // connect to mysql 
    include('../cgi-bin/db.php'); 

    $username = $HTTP_POST_VARS['username']; 
    $password = md5($HTTP_POST_VARS['password']); 

    if(!$db) 
    { 
     echo 'Cannot connect to database.'; 
     exit; 
    } 
    // select the appropriate database 
    $mysql = mysql_select_db('quickwebcms'); 
    if(!$mysql) 
    { 
     echo 'Cannot select database.'; 
     exit; 
    } 

    // query the database to see if there is a record which matches 
    $query = "select count(*) from auth where 
       username = '$username' and 
       password = '$password'"; 

    $result = mysql_query($query); 
    if(!$result) 
    { 
     echo 'Cannot run query.'; 
     exit; 
    } 

    $count = mysql_result($result, 0, 0); 

    if ($count > 0) 
    { 
     // visitor's name and password combination are correct 
     echo '<h1>Here it is!</h1>'; 
     echo 'I bet you are glad you can see this secret page.'; 
    } 
    else 
    { 
     // visitor's name and password combination are not correct 
     echo '<h1>Go Away!</h1>'; 
     echo 'You are not authorized to view this resource.'; 
    } 
    } 
?> 
+0

mysql_error()說連接的問題是什麼? – 2009-10-16 23:24:13

回答

4

我猜這可能是因爲$HTTP_POST_VARS。嘗試用$_POST代替。如果還是不行,請嘗試將下面的代碼片段<?php後右:

 
// Enable displaying errors 
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
相關問題