Php 显示带有cookie的用户名
我已经在php和mysql之间创建了一个连接,并且在mysql表中添加了用户名和密码,这样我就可以登录并重定向到“成员”页面。它在这一点上起作用,但我想做的是在我的“成员”页面的某些地方显示“用户名”和cookies 在first.php上,在navbar上,blockquote上面写着“User”,我想用登录的用户名替换它,但是用cookies替换,我不知道怎么做 我的文件: config.phpPhp 显示带有cookie的用户名,php,html,mysql,database,Php,Html,Mysql,Database,我已经在php和mysql之间创建了一个连接,并且在mysql表中添加了用户名和密码,这样我就可以登录并重定向到“成员”页面。它在这一点上起作用,但我想做的是在我的“成员”页面的某些地方显示“用户名”和cookies 在first.php上,在navbar上,blockquote上面写着“User”,我想用登录的用户名替换它,但是用cookies替换,我不知道怎么做 我的文件: config.php <?php $mysql_hostname="localhost"; $m
<?php
$mysql_hostname="localhost";
$mysql_user="root";
$mysql_password="root";
$mysql_database="Electricians";
$bd=mysql_connect($mysql_hostname,$mysql_user,$mysql_password)or die("Bad Connection");
mysql_select_db($mysql_database,$bd)or die("Bad Connection");
?>
index.php
<?php
header("location:login.php");
?>
login.php
<?php
session_start();
include("includes/config.php");
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$myusername=addslashes($_POST ['username']);
$mypassword=md5(addslashes($_POST[ 'password']));
$sql="SELECT userid FROM users WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
$_SESSION['login_admin']=$myusername;
header("location:http://localhost:8888/offlineproject/first.php");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/theme.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/csc" href="css/bootstrap-glyphicons.css">
<link rel="stylesheet" type="text/csc" href="css/login.css">
<title>Online Drawing for Electricians</title>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-header">
<a class="navbar-brand" href="#"><img id="logoattop" src="images/nklogo.png" alt="Logo" >Online Drawing for Electricians </a>
</div>
</div>
</nav><
<div class="jumbotron">
<div class="container text-center">
<h1>Online Drawing for Electricians</h1>
<div class="container">
<form class="form-signin" method="post">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputEmail" class="sr-only">Email address</label>
<input name="username" type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input name="password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
<a href="first.php">Skip</a>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-2.1.3.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
电工在线绘图
<
电工在线绘图
请登录
电子邮件地址
密码
登录
first.php
<!Doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/theme.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link href="css/bootstrap-glyphicons.css"rel="stylesheet">
<title>Online Drawing for Electricians</title>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!navbar header-->
<div class="navbar-header">
<a class="navbar-brand" href="#"><img id="logoattop" src="images/nklogo.png" alt="Logo" >Online Drawing for Electricians </a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href=#><span class="glyphicon glyphicon-user"></span> <User></a></li>
<li><a href="/offlineproject/logout.php"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
</ul>
</div>
</div><!End-Container-->
</nav><!End-Nav-Bar-->
<div class="jumbotron">
<div class="container text-center">
<h1>Online Drawing for Electricians</h1>
<div class="btn-group">
<a href="" class="btn btn-lg btn-warning ">Search</a>
<a href="" class="btn btn-lg btn-default ">Upload</a>
</div>
</div>
</div> <!End Jumbotron-->
<!Blockquotes-->
<div class="container">
<section>
<div class= "page-header" id="feedback">
<h2>Recent activity of <small><User></small></h2>
</div>
<div class="row">
<div class="col-lg-12">
<blockquote>
<p>"User" Today job is to fix the cables of the central bank.</p>
<p>Cables need to be fixed as soon as possible </p>
<footer>NK Electrical LTD</footer>
</blockquote>
</div>
<div class="col-lg-12">
<blockquote>
<p>Something Something
SomethingSomething
SomethingSomethingSomething</p>
<footer>Aris Con</footer>
</blockquote>
</div>
</div>
</section>
<a href="planedit.php">Skip</a>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-2.1.3.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
电工在线绘图
电工在线绘图
最近的活动
“用户”今天的工作是修复中央银行的电缆
电缆需要尽快固定
NK电气有限公司
什么东西
某物某物
某物某物某物某物
阿里斯监狱
logout.php
<?php
session_start();
if(session_destroy())
{
header("location: index.php");
}
?>
仅仅因为设置了用户/通行证,您不能假定他们是管理员,除非进行了进一步的检查。通过数据库中的标志或通过在某处匹配硬编码值 所以你需要把它改成这样:
$sql="SELECT userid FROM users WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$row = mysql_fetch_assoc($result);
if($row['is_admin'] == '1'){
$_SESSION['login_admin']=$myusername;
header("location:http://localhost:8888/offlineproject/first.php");
exit;
}
else{
// do something else here
}
}
}
试试这套饼干
$first_name = 'Rilakkuma';
setcookie('first_name',$first_name,time() + (86400 * 7)); // 86400 = 1 day
打电话给cookie
$_COOKIE['first_name'];
请参阅此处的详细信息-->$first\u name=“user”
然后设置cookie();使用这个设置cookie
$COOKIE['first_name']Sidenote:您正在使用旧的和不安全的函数,例如MD5,而没有对任何内容进行消毒。我希望这是为了教育目的,而不是为了生活。这是完全不安全的;只需在那里使用会话,拉入会话数组并回显它;我喜欢晚餐。你不需要用cookies来做这个。