永发信息网

php网页登录,为什么验证不通过,登陆不进去,输入正确的账号密码还是提示先登录?帮忙看一下

答案:2  悬赏:0  手机版
解决时间 2021-01-29 09:29
  • 提问者网友:杀手的诗
  • 2021-01-28 12:21
pass.php<br>&lt;?php<br>header(&quot;Content-type:text/html;charset=utf-8&quot;);<br>   session_start() ;<br> require(&quot;conn.php&quot;);<br> //echo 'test';exit;<br><br>    $pass=$_POST[&quot;password&quot;];<br>   //$username = $_POST['name'];<br> $sql=&quot;select * from admin where name='&quot;.$_POST[&quot;name&quot;].&quot;'and password='&quot;.$pass.&quot;'&quot;;<br> //$sql = &quot;select password,tel from admin where name = '$username'&quot;;<br> $result=mysql_query($sql) or die(mysql_error());<br> if(!$result){<br> header(&quot;Location:index.php?msg=用户名不存在&quot;);<br> exit;<br> }<br> $rs=mysql_fetch_assoc($result);<br><br> if($pass != $rs['password']){<br> header(&quot;Location:index.php?msg=密码有误&quot;);<br> exit;<br> }<br> //var_dump($rs);echo '--'.$pass;exit;<br> $_SESSION['username'] = $username;<br> $_SESSION['tel'] = $rs['tel'];<br> header(&quot;Location:home.php&quot;);<br>?&gt;<br>登陆页面<br>index.php<br>&lt;!doctype html&gt;<br>&lt;html lang=&quot;en&quot; class=&quot;no-js&quot;&gt;<br>&lt;head&gt;<br>&lt;meta charset=&quot;utf-8&quot;&gt;<br>&lt;meta content=&quot;width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0&quot; name=&quot;viewport&quot;&gt;<br>&lt;meta content=&quot;yes&quot; name=&quot;apple-mobile-web-app-capable&quot;&gt;<br>&lt;meta content=&quot;black&quot; name=&quot;apple-mobile-web-app-status-bar-style&quot;&gt;<br>&lt;meta name=&quot;format-detection&quot; content=&quot;telephone=no&quot;&gt;<br>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>&lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot;&gt;<br>&lt;title&gt;车票预订&lt;/title&gt;<br>&lt;script  language=&quot;javascript&quot; type=&quot;text/javascript&quot; &gt;<br> function check(){<br> if($('username').value == ''){<br> alert('用户名不能为空!');<br> }<br> if($('password').value == ''){<br> alert('手机号不能为空!');<br> } <br> }<br> function $(id){<br> return document.getElementById(id);<br> }<br><br>&lt;/script&gt;<br><br>&lt;/head&gt;<br><br>&lt;body&gt;<br>&lt;div id=&quot;index&quot; style=&quot;background-image:url(images/bg.jpg);&quot;&gt;<br>&lt;div class=&quot;page-container&quot;&gt;<br>  &lt;h1&gt;登陆&lt;/h1&gt;<br>     &lt;form name=&quot;LoginForm&quot; action=&quot;pass.php&quot; method=&quot;post&quot;&gt;<br>       &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;username&quot; placeholder=&quot;输入用户名&quot; autofocus required&gt;<br>       &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot; placeholder=&quot;输入密码!&quot; required&gt;<br>       &lt;input type=&quot;checkbox&quot; checked=&quot;checked&quot; class=&quot;Captcha&quot;&gt;<br>       &lt;span style=&quot;font-size: 18px;float:left;margin-top:20px;&quot; &gt;自动登录&lt;/span&gt; <br>       &lt;button type=&quot;submit&quot; class=&quot;submit_button&quot; onClick=&quot;check()&quot;&gt;确定&lt;/button&gt;<br>     &lt;/form&gt;<br>     &lt;p&gt;&lt;font color='red'&gt;&lt;?php echo @$_GET['msg']?&gt;&lt;/font&gt;&lt;/p&gt;<br>&lt;/div&gt;<br>&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br>数据库<br> id  name  password  <br>1  admin  admin  <br>2  lily  12345<br>conn.php<br>&lt;?php <br>$conn =@mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;12345&quot;);<br>   if (!$conn){<br>      die(&quot;数据库连接失败: &quot; . mysql_error());<br>    }<br>   mysql_select_db(&quot;hr&quot;,$conn);<br>   mysql_query(&quot;set character set 'utf8'&quot;);<br>   mysql_query(&quot;set names 'utf8'&quot;);<br>?&gt;
最佳答案
  • 五星知识达人网友:廢物販賣機
  • 2021-01-28 13:49
判断session前,需要先使用session_start()启用会话
session_start();
if(isset($_SESSION['username'])){
//用户已经登陆

}else{
//用户未登录或登陆超时

}
全部回答
  • 1楼网友:一叶十三刺
  • 2021-01-28 14:59

    更改你显示器的分辩率!!

    1024*768一般是这么多!!!

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯