[英]PHP/MySQL login works on one server (PHP 5.0.2) but does not work on the other (PHP 5.1.6)
Here is a stripped down version of what I use to authenticate users, it works fine on my PHP v5.0.2/MySQL 4.0.21 server, but fails on my PHP v5.1.6/MySQL v5.0.45 server. 这是我用来验证用户身份的精简版本,在我的PHP v5.0.2 / MySQL 4.0.21服务器上可以正常工作,但在我的PHP v5.1.6 / MySQL v5.0.45服务器上无法正常工作。
In the code below, should I be aware of anything that might not be supported by the newer version of PHP & MySQL? 在下面的代码中,我是否应该知道较新版本的PHP和MySQL不支持的任何内容? Global variables have been enabled. 全局变量已启用。
<?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.';
}
}
?>
I'm guessing it might be because of $HTTP_POST_VARS
. 我猜可能是因为$HTTP_POST_VARS
。 Try replacing that with $_POST
. 尝试将其替换为$_POST
。 If it still doesn't work, try putting the following snippet right after <?php
: 如果仍然无法正常运行,请尝试在<?php
之后添加以下代码段:
// Enable displaying errors
error_reporting(E_ALL);
ini_set('display_errors', '1');
Try setting register_long_arrays = On in php.ini and see if that fixes your issues. 尝试在php.ini中设置register_long_arrays = On,看看是否可以解决您的问题。
On another note you shouldn't be building your queries up like that. 另一方面,您不应该那样建立查询。 Look into using PHP MySQL escaping . 研究如何使用PHP MySQL转义 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.