Я создал соединение между php и mysql, и я добавил имя пользователя и пароль в таблице mysql, чтобы я мог войти и перенаправить на страницу «участники». Он работает на этом этапе, но я хочу показать «имя пользователя» в некоторых местах на моей странице «Пользователи» с помощью файлов cookie.Показать имя пользователя с кукисами
На first.php, на навигационной панели, BLOCKQUOTE, где он говорит, что «пользователь» Вот где я хочу, чтобы заменить его с именем пользователя, логины, но с печеньем и я не понял, как это сделать
Мои файлы :
config.php
<?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");
?>
л ogin.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>
logout.php
<?php
session_start();
if(session_destroy())
{
header("location: index.php");
}
?>
Sidenote: Вы используете старые и небезопасные функции, такие как MD5, например, и ничего не дезинфицировать. Я надеюсь, что это будет в образовательных целях и не предназначено жить. Это совершенно небезопасно. –
Чтобы ответить на это; просто используйте сеансы там, потяните за массив сеанса и эхом откройте его; * сделано подобный ужин *. Для этого вам не нужно использовать файлы cookie. –