首页 / PHP / PHP / MySQL登录
PHP / MySQL登录
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP / MySQL登录,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3096字,纯文字阅读大概需要5分钟。
内容图文
![PHP / MySQL登录](/upload/InfoBanner/zyjiaocheng/890/dc027594d80349d7b61e4aea09675501.jpg)
我正在尝试创建简单的登录表单.
的login.php
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$myusername=addslashes($_POST['username']);
$mypassword=addslashes($_POST['password']);
$sql="SELECT id FROM login_test WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
session_register("myusername");
$_SESSION['login_user']=$myusername;
//echo $_SESSION['login_user'];
header("location: welcome.php");
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>
<!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=iso-8859-1" />
<title>Login Page</title>
<style type="text/css">
body
{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
}
label
{
font-weight:bold;
width:100px;
font-size:14px;
}
.box
{
border:#666666 solid 1px;
}
</style>
</head>
<body bgcolor="#FFFFFF">
<div style="font-weight:bold; margin-bottom:10px">Demo Login Details -> Username : <a href="#">test</a> Password : <a href="#">test</a></div>
<div align="center">
<div style="width:300px; border: solid 1px #333333; " align="left">
<div style="background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
<div style="margin:30px">
<form action="" method="post">
<label>UserName :</label><input type="text" name="username" class="box"/><br /><br />
<label>Password :</label><input type="password" name="password" class="box" /><br/><br />
<input type="submit" value=" Submit "/><br />
</form>
<div style="font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>
</div>
</div>
</div>
</body>
</html>
lock.php
<?php
include('config.php');
session_start();
$user_check=$_SESSION['login_user'];
$ses_sql=mysql_query("SELECT username FROM login_test WHERE username='$user_check' ");
$row=mysql_fetch_array($ses_sql);
$login_session=$row['username'];
if(!isset($login_session))
{
header("Location: login.php");
}
?>
的welcome.php
<?php
include('lock.php');
?>
<!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=iso-8859-1" />
<title>Welcome </title>
</head>
<body>
<h1>Welcome <?php echo $login_session; ?></h1>
<h2>Login succesfull</h2>
<h2><a href="logout.php">Sign Out</a></h2>
</body>
</html>
问题是它一直重定向回login.php,lock.php启动,我不确定是什么问题
当我输入错误的用户名密码时,它会正确显示消息
解决方法:
问题出在这里
if($count==1)
{
session_register("myusername");
^ // this is deprecated
$_SESSION['login_user']=$myusername;
//echo $_SESSION['login_user'];
header("location: welcome.php");
}
不要使用session_register,不推荐使用它
使用此代码直接使用它
$_SESSION['login_user']="myusername";
内容总结
以上是互联网集市为您收集整理的PHP / MySQL登录全部内容,希望文章能够帮你解决PHP / MySQL登录所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。