无法登录到所需的位置 [英] not able to login to the desired location

查看:170
本文介绍了无法登录到所需的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

未定义索引:C:\wamp\www\Website\storeadmin\admin_login.php..中的用户名密码






  // admin_login。 php 
<?php
session_start();
if(isset($ _ SESSION [member])){
header(location:index.php);
exit();
}

?>
<?php
if(isset($ _ POST [username])&&& isset($ _ POST [password])){//< - 检查用户是否点击按钮
$ manager = preg_replace('#[A-Za-z0-9] #i',,$ _ POST [username]);
$ password = preg_replace('#[A-Za-z0-9] #i',,$ _ POST [password]);



包括../storescripts/connect_to_mysql.php;
$ sql = mysql_query(SELECT * FROM admin WHERE username ='$ manager'AND password ='$ password'LIMIT 1);
$ exists_count = mysql_num_rows($ sql);
if($ exists_count == 1){
while(mysql_fetch_array($ sql)){
$ id = $ row [id];
}

$ _SESSION [id] = $ id;
$ _SESSION [manager] = $ manager;
$ _SESSION [password] = $ password;
header(location:index.php);
exit();

}
else {
echo'此信息不正确,请重试< a href =index.php>点击此处< / a>';
exit();
}
}




?>
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title> AdminLogin< / title>
< link rel =stylesheethref =../ style / style.csstype =text / cssmedia =screen/>
< / head>

< body>
< div id =mainWrapper>
<?php include_once(../ template_header.php);?>
< div id =pageContent>
< div align =leftstyle =margin-left:040px;>< h1>请先登录才能继续< / h1>< br />
< / div>
< form id =form1name =form1method =postaction =admin_login.php>
UserName< br />
< input type =textname =usernameid =usernamesize =40/>
Password< br />
< input type =passwordname =password id =passwordsize =40/>
< br />
< br />
< br />
< input type =submitname =buttonid =buttonvalue =LogIn/>
< / form>
< / div>
<?php include_once (../template_header.php\");?>
< / div>
< / body>
< / html>
//index.php
<?php
session_start();
if(!isset($ _ SESSION [member])){
header(location:admin_login.php);
exit();
}

$ managerID = preg_replace('#[^ 0-9] #i',,$ _ SESSION [id]);
$ manager = preg_replace('#[A-Za-z0-9] #i',,$ _ SESSION [manager]);
$ password = preg_replace('#[A-Za-z0-9] #i',',$ _ SESSION [password]);


包括../storescripts/connect_to_mysql.php;
$ sql = mysql_query(SELECT * FROM admin WHERE id ='managerID'AND username ='$ manager'AND password ='$ password'LIMIT 1);
$ exists_count = mysql_num_rows($ sql);
if($ exists_count == 0){
echo(您的登录会话数据不在数据库中);
exit();
}



?>
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns =http://www.w3.org/1999/xhtml>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>服务管理区域< / title>
< link rel =stylesheethref =../ style / style.csstype =text / cssmedia =screen/>
< / head>

< body>
< div id =mainWrapper>
<?php include_once(../ template_header.php);?>
< div id =pageContent>
< div align =leftstyle =margin-left:040px;>< h1> Hello Store Manager。您今天愿意做什么< / h1>< br /
< h3>< a href =inventory_list.php>管理库存< / a>< / h3>< br />< h3>< a href =管理我< / a>< / h3>< br />< / div>< / div>
<?php include_once(../ template_header.php);?&
< / div>
< / body>
< / html>


b $ b

我面临的问题是,我不能登录到我的 index.php 页面,即使我已经输入正确的用户名和密码后,指定在我的数据库中,我通过phpmyadmin设置每次我尝试登录它调用 echo'这信息不正确,再试一次点击这里如<$

解决方案
>

尝试一些调试;




  • 先检查$ _POST ['username']和$ _POST ['password']的值

  • 在您对mysql_query()的调用中添加'or die mysql_error()',看看是否运行正常

  • 回显$ sql的值,以便查看查询。

  • header()命令不需要在名称和值之间有空格?或者\r\\\
    之后?值得仔细检查。

  • 通常在各个阶段提供更多的输出,而且应该很少跟踪问题。



并且(一旦工作),请在数据库的密码字段中添加一个crypt()或md5()+ salt。


Possible Duplicate:
Undefined index: username in C:\wamp\www\Website\storeadmin\admin_login.php..and the same for password

//admin_login.php
<?php
session_start();
if(isset($_SESSION["member"])){
    header("location:index.php");
    exit();
}

?>
<?php
if(isset($_POST["username"]) && isset($_POST["password"])){     // <-  Check the user has clicked the button
  $manager = preg_replace('#[A-Za-z0-9]#i',"",$_POST["username"]);
  $password = preg_replace('#[A-Za-z0-9]#i',"",$_POST["password"]);



include "../storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM admin WHERE username ='$manager' AND password ='$password'LIMIT 1");
$exist_count = mysql_num_rows($sql);
if($exist_count == 1){
    while(mysql_fetch_array($sql)){
        $id = $row["id"];
        }

    $_SESSION["id"]= $id;
    $_SESSION["manager"]= $manager;
    $_SESSION["password"]= $password;
    header("location:index.php");
    exit();

    }
    else{
    echo 'This information is incorrect,try again <a href = "index.php">Click Here</a>';
    exit();
    }
}




?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> AdminLogin</title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/>
</head>

<body>
<div  id="mainWrapper" > 
    <?php include_once("../template_header.php");?>
    <div id="pageContent" > 
    <div align="left" "style="margin-left:040px;"><h1>Please login to continue</h1><br />
    </div>
    <form id="form1" name="form1" method="post" action="admin_login.php"> 
    UserName<br />
    <input type="text" name="username" id="username" size="40"/>
    Password<br />
    <input type="password" name="password" id="password" size="40"/> 
    <br />
    <br />
    <br /> 
    <input type="submit" name="button" id="button" value="LogIn"/>  
    </form>
    </div>
    <?php include_once("../template_header.php");?>
</div>
</body>
</html>
//index.php
<?php
session_start();
if(!isset($_SESSION["member"])){
    header("location:admin_login.php");
    exit();
}

$managerID = preg_replace('#[^0-9]#i',"",$_SESSION["id"]);
$manager = preg_replace('#[A-Za-z0-9]#i',"",$_SESSION["manager"]);
$password = preg_replace('#[A-Za-z0-9]#i',"",$_SESSION["password"]);


include "../storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM admin WHERE id ='managerID' AND username ='$manager' AND password ='$password'LIMIT 1");
$exist_count = mysql_num_rows($sql);
if($exist_count == 0){
    echo("Your login session data in not in the database");
    exit();
}



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Service Admin Area</title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/>
</head>

<body>
<div  id="mainWrapper" > 
    <?php include_once("../template_header.php");?>
    <div id="pageContent" > 
    <div align="left" "style="margin-left:040px;"><h1>Hello Store Manager .What would you loke to do today</h1><br />
    <h3><a href="inventory_list.php">Manage Inventory</a></h3><br/><h3><a href="">Manage Me</a></h3><br/></div></div>
    <?php include_once("../template_header.php");?>
</div>
</body>
</html>

The problem I am facing is that I am not able to login to my index.php page even after I have put in the correct username and password as specified in my database which I have set through phpmyadmin. Everytime I try to login it invokes the echo 'This information is incorrect,try again Click Here' as mentioned in the admin_login.php. I am getting a bit frustrated. Can you help me out guys?

解决方案

Try some debugging;

  • Check the values of $_POST['username'] and $_POST['password'] before and after your preg_replace calls.
  • Add an 'or die mysql_error()' to your call to mysql_query() to see if that is running ok
  • Echo out the value of $sql so you can have a look at the query.
  • Does the header() command not require a space between the name and value? or a \r\n afterwards? Worth double-checking.
  • Generally provide more output at various stages and it should be trivial to track down the issue.

And (once it is working), please please add a crypt() or md5() + salt to your password field in the database.

这篇关于无法登录到所需的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆