使用php和html创建登录页面

时间:2015-03-13 16:43:08

标签: php html

想要创建一个登录,用户可以在其中注册一个站点,然后他们就可以登录。我是要添加到phpmyadim中的数据的详细信息,当用户登录时,我想要详细信息从数据库中获取。我已经知道如何做到这一点,但我想知道的是我如何得到它,当用户登录时将它们带回主页,右手conner它说“hello emma”(或任何登录的人)

这是我的代码

登录

?php
	//Start session
	session_start();	
	//Unset the variables stored in session
	unset($_SESSION['SESS_MEMBER_ID']);
	unset($_SESSION['SESS_FIRST_NAME']);
	unset($_SESSION['SESS_LAST_NAME']);
?>

<form name="loginform" action="mylogin.php" method="post">
<table width="309" border="0" align="center" cellpadding="2" cellspacing="5">
  <tr>
    <td colspan="2">
		<!--the code bellow is used to display the message of the input validation-->
		 <?php
			if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
			echo '<ul class="err">';
			foreach($_SESSION['ERRMSG_ARR'] as $msg) {
				echo '<li>',$msg,'</li>'; 
				}
			echo '</ul>';
			unset($_SESSION['ERRMSG_ARR']);
			}
		?>
	</td>
  </tr>
  <tr>
    <td width="116"><div align="right">Username</div></td>
    <td width="177"><input name="username" type="text" /></td>
  </tr>
  <tr>
    <td><div align="right">Password</div></td>
    <td><input name="password" type="password" /></td>
  </tr>
  <tr>
    <td><div align="right"></div></td>
    <td><input name="" type="submit" value="login" /></td>
  </tr>
</table>
</form>

检查登录

<?php
	//Start session
	session_start();
	//Check whether the session variable SESS_MEMBER_ID is present or not
	if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
		header("location: myindex.php");
		exit();
	}
?>

我的主页

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
	 <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Home</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="advertising.css">
		
<?php
session_start();


?>

		<div id = "menu">

			<div id='welcome'>
    <?php 
   
        if(isset($_SESSION['username']))
        {
            echo 'Welcome ' . $_SESSION['username']; 
        }
    ?>
</div>
</div>
		
	</head>
	<body>
	
	<header>
		
		<nav>
			<ul>
				<li><a href="index.html"><img src="../img/buzz_party.png" class="imglogo"></a></li>
                <li><a href="index.html">Home</a></li>
				<li><a href="aboutus.html">About us</a></li>
				<li><a href="contact.html">Contact</a></li>
                <li><a href="advertising.html">Supplies</a></li>


                <li><a href ="logintest.php">Login</a></li>

                <li><a href="register.php">Register</a></li>
                
			</ul>
		</nav>
	</header>
	
	
		
		<div id="slideshow">
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nisl est, fringilla eget sem in, viverra ornare enim. Fusce ac finibus leo. Nullam quis mauris nunc. Sed in 
			ipsum consectetur, faucibus justo quis, suscipit tortor. Vestibulum sed augue egestas justo dictum sagittis. Nam eu enim blandit lacus accumsan hendrerit eu eget lorem. Nullam 
			sed augue dictum sapien mattis accumsan. Mauris arcu ligula, mattis in blandit vitae, vehicula quis mi. Integer tempor felis ac vulputate semper. Proin sed mauris at orci facilisis 
			luctus id vel nibh. Proin egestas suscipit nulla, ac ornare erat imperdiet a. Integer convallis volutpat pretium. Mauris ac.</p>
		</div>
		
		<div  id="container">
			<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam placerat pulvinar urna, ac dapibus lectus iaculis et. Suspendisse eu velit commodo, 
			aliquet eros vitae, vehicula nibh. Integer ante est, scelerisque id fermentum sed, sagittis dignissim neque. Proin id felis ante. Praesent sed massa in tellus consectetur maximus. 
			Quisque auctor sem ac felis sagittis, non imperdiet tortor tincidunt. Quisque at lorem vitae mi posuere aliquet. In hac habitasse platea dictumst. Praesent ultrices, enim non blandit 
			ullamcorper, odio orci vulputate mauris, in congue nulla elit a turpis.</p>

			<p>Aenean tempus risus ac enim cursus, id varius dolor aliquam. Donec mauris tortor, efficitur ut condimentum sit amet, pellentesque in nisl. Duis mattis nisi non congue ullamcorper. 
			In rhoncus lobortis vulputate. Pellentesque lacinia finibus libero, elementum volutpat lectus faucibus vitae. Quisque interdum ipsum et rutrum aliquet. Lorem ipsum dolor sit amet, consectetur 
			adipiscing elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam at libero nec velit euismod consectetur. Nulla facilisi. Pellentesque placerat 
			sapien felis, sit amet auctor nisl eleifend ut. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vel justo a turpis commodo laoreet scelerisque posuere odio. Duis pellentesque 
			metus sed egestas vestibulum. In elit ante, gravida sed hendrerit quis, dapibus quis felis.</p>

			<p>Pellentesque commodo finibus tempus. Donec lobortis ut est sit amet imperdiet. Morbi et tortor at turpis dapibus vulputate. Curabitur ornare leo leo. In justo tortor, semper ac dui eu, 
			luctus gravida felis. Mauris dui diam, consectetur tincidunt aliquet vitae, tempus sed urna. Suspendisse facilisis, mauris sed dapibus suscipit, odio orci imperdiet est, in vulputate odio 
			lectus ut lacus. Curabitur eros dui, eleifend vel pretium vel, semper non felis. </p>
		</div>
	</body>
</html>

1 个答案:

答案 0 :(得分:1)

这可能不是问题,但在您编写的登录文件开头的代码段中

?php

这可能是复制粘贴错误,但如果不是,则需要编写

<?php

(添加开头胡萝卜)