Php Http URL保护在localhost中工作,但在服务器上失败
我正在使用验证我的URLPhp Http URL保护在localhost中工作,但在服务器上失败,php,mysql,http,url,Php,Mysql,Http,Url,我正在使用验证我的URL 它在我的localhost中运行良好,但当我加载到服务器(goDaddy)时,它会反复询问用户名和密码 我想控制这些用户名和密码字段,并将它们连接到我的数据库 为此,我使用如下代码: $conid = mysql_connect("localhost", "root", ""); if(!$conid) { die("sorry unable to establish a connection".mysql_error()); } echo "connected s
localhost
中运行良好,但当我加载到服务器(goDaddy)时,它会反复询问用户名和密码$conid = mysql_connect("localhost", "root", "");
if(!$conid) {
die("sorry unable to establish a connection".mysql_error());
}
echo "connected succesfully<br>";
mysql_select_db("passurl", $conid);
$rr = mysql_query("select password from validate where username='$user' ");
while($row = mysql_fetch_array($rr)) {
$x = $row['password'];
}
if($x == $password) {
//take into the website
}
和auth.php
包含
<?php
$_user_ = 'test';
$_password_ = 'test';
session_start();
$url_action = (empty($_REQUEST['action'])) ? 'logIn' : $_REQUEST['action'];
$auth_realm = (isset($auth_realm)) ? $auth_realm : '';
if (isset($url_action)) {
if (is_callable($url_action)) {
call_user_func($url_action);
} else {
echo 'Function does not exist, request terminated';
};
};
function logIn() {
global $auth_realm;
if (!isset($_SESSION['username'])) {
if (!isset($_SESSION['login'])) {
$_SESSION['login'] = TRUE;
header('WWW-Authenticate: Basic realm="'.$auth_realm.'"');
header('HTTP/1.0 401 Unauthorized');
echo 'You must enter a valid login and password';
echo '<p><a href="?action=logOut">Try again</a></p>';
exit;
} else {
$user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
$password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
$result = authenticate($user, $password);
if ($result == 0) {
$_SESSION['username'] = $user;
} else {
session_unset($_SESSION['login']);
errMes($result);
echo '<p><a href="">Try again</a></p>';
exit;
};
};
};
}
function authenticate($user, $password) {
global $_user_;
global $_password_;
if (($user == $_user_)&&($password == $_password_)) { return 0; }
else { return 1; };
}
function errMes($errno) {
switch ($errno) {
case 0:
break;
case 1:
echo 'The username or password you entered is incorrect';
break;
default:
echo 'Unknown error';
};
}
function logOut() {
session_destroy();
if (isset($_SESSION['username'])) {
session_unset($_SESSION['username']);
echo "You've successfully logged out<br>";
echo '<p><a href="?action=logIn">LogIn</a></p>';
} else {
header("Location: ?action=logIn", TRUE, 301);
};
if (isset($_SESSION['login'])) { session_unset($_SESSION['login']); };
exit;
}
?>
您需要在goDaddy托管服务上创建数据库用户名和密码,root
和空密码无法让您通过。根用户是本地服务器的默认用户名,您没有为其设置任何密码,因此“
可用作密码。您必须在远程服务器上设置用户名和密码才能使其工作
mysql_connect("your-host-server", "a-username", "a-secret-password"); // Password can't be empty and username can't be root, hope you understand
您需要在goDaddy托管服务上创建数据库用户名和密码,root
和空密码无法让您通过。根用户是本地服务器的默认用户名,您没有为其设置任何密码,因此“
可用作密码。您必须在远程服务器上设置用户名和密码才能使其工作
mysql_connect("your-host-server", "a-username", "a-secret-password"); // Password can't be empty and username can't be root, hope you understand
您正在paswords上循环,但只在循环后检查一个值
您的代码是:
while($row = mysql_fetch_array($rr)) {
$x = $row['password'];
}
if($x == $password) {
//take into the website
}
应该是:
while($row = mysql_fetch_array($rr)) {
if ($password == $row['password']) {
// take into the website
}
}
您正在paswords上循环,但只在循环后检查一个值
您的代码是:
while($row = mysql_fetch_array($rr)) {
$x = $row['password'];
}
if($x == $password) {
//take into the website
}
应该是:
while($row = mysql_fetch_array($rr)) {
if ($password == $row['password']) {
// take into the website
}
}
正确的格式请您出示完整的实际代码。还要验证数据库连接是否在您的公用主机上工作。@DaveRandom完整代码与提供的链接中的代码相同。请正确设置格式。请显示完整的实际代码。还要验证数据库连接是否在您的公共主机上工作。@DaveRandom完整代码与提供的链接中的代码相同。我以前有过一些关于如何使数据库联机的经验,并且没有任何问题。首先,它不能在本地工作。我以前有一些关于如何在线创建数据库的经验,没有任何问题。首先,它不能在本地工作。