Am using this代码用于认证我的URL。
其工作罚款载于我的<代码> 当地东道,但在我装上服务器(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
}
因此,用户名和密码在成功认证后进入该页。
Am using PHP-MYSQL, as I ve preliminary knowledge in it, am newbie to programming.
帮助我确定上述两个问题,并制定适当的测试守则。
Edit:
Issue one is working locally and am using the same code as provided in the link. Issue two is am trying to retrieve those username
and password
fields from my local database so as login can be granted, on my localhost(if it works on later stage I ll take the database to online).
Edit-2:
<代码>ty.php 守则
<?php
$auth_realm = Access restricted ;
require_once auth.php ;
echo "You ve logged in as {$_SESSION[ username ]}<br>";
echo <p><a href="?action=logOut">LogOut</a></p>
?>
<center><h1>now you see the protected content</h1></center>
www.un.org/spanish/ga/president 页: 1
<?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;
}
?>
一旦我们打上了<代码>ty.php,它就要求用户名称和密码,并成功验证该密码显示受保护。 所有这一切都在当地进行罚款,但是没有在服务器上工作。
Can someone pls help me out of this
Thanks in advance :)