我想重定向到adm/index.php
文件if($count==1)
,但该页面只是刷新并停留在同一页面上。
我尝试了几种解决方案无济于事:
<?php>
<?php>
一切都在xxamp本地运行良好,但问题是在上传后,没有错误信息;只是同一页刷新,它是空白的。
在主程序中调用两个函数;主程序还包含一些回声。是否可以使标题有效?
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM adminlogin WHERE username = '$myusername' and password ='$mypassword'";
$result=mysql_query($sql); // from adminlogin table, ngetasacco
$sql2="SELECT * FROM memberslogin WHERE username = '$myusername' and password ='$mypassword'";
$result2=mysql_query($sql2); // from the memberslogin table, ngetasacco
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
$count2 = mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)// only the admin
{
$_SESSION['myusername'] = myusername;
$_SESSION['mypassword'] = mypassword;
header("location: adm/index.php");
}
elseif($count2==1)// any registered member with access
{
$_SESSION['myusername'] = myusername;
$_SESSION['mypassword'] = mypassword;
header("location: adm/member.php");
}
else {
echo "<musuya>Wrong username or Password</musuya><br/><br/>";
//echo md5($mypassword);
//$m=md5($mypassword);
usernamePass();
}
ob_end_flush();
}// end of function auth()
function usernamePass()
{
echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . ">";
echo " username <input type='text' name='username' /><br/><br/>";
echo "password <input type='password' name='password' value=''/><br/>";
echo "<input type='submit' value='Login' />";
}// end of function usernamePass()
//++++++++++++++++++++++++++main program
+++++++++++++++++++++++++++++++++++
if(empty($_POST["username"]) || empty($_POST["password"]))
{
echo"username and pasword cannot be empty</br></br>";
usernamePass();
}
if(!(empty($_POST["username"])) && !(empty($_POST["password"])))
{
auth();
}
if(!empty($_GET['status']))
{
echo '<div>You have been logged out!</div>';
}
//++++++++++++++++++++++++ end of main program
++++++++++++++++++++++++++++++
?>
<?php
$host="";// Host name
$username="";//Mysql username
$password="";//Mysql password
$db_name="";//Database name
$tbl_name="";//Table name
//Connect to server and select databse.
mysql_connect("$host", "$username", "$password");//or die("cannot connect");
mysql_select_db("$db_name");//or die("cannot select DB");
//echo "connected to server and dbase";
?>
答案 0 :(得分:0)
将ob_end_flush();
添加到文件底部并进行检查
<?php
function auth(){
ob_start();
include"connections/db_connect.php";
// Define $myusername and $mypassword
$myusername=md5($_POST['username']);
$mypassword=md5($_POST['password']);
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM adminlogin WHERE username = '$myusername' and password = '$mypassword'";
$result=mysql_query($sql); // from adminlogin table, ngetasacco
$sql2="SELECT * FROM memberslogin WHERE username = '$myusername' and password = '$mypassword'";
$result2=mysql_query($sql2); // from the memberslogin table, ngetasacco
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
$count2 = mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row
//if($count==1){
if($count==1)// only the admin
{
$_SESSION['myusername'] = myusername;
$_SESSION['mypassword'] = mypassword;
//header("location: login_success.php");
header("location: adm/index.php");
}
ob_end_flush();
?>