我有一个简单的HTML网站,想通过php登录来限制它的一些页面


i have a simple HTML site and want to restrict its some pages via php login

下面是我想为普通用户限制的页面的HTML。当有人试图访问此页面时,他/她必须登录才能查看页面的详细信息。请在这方面提供指导。我该怎么做?

<head>
<title>Welcome to ULTRATEC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<!-- Cufon -->
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/myradpro.font.js"></script>
<script type="text/javascript">
Cufon.replace('h1')('h2')('h3')('h4')('div.menu li');
</script>
<!-- flash script -->
<script type="text/javascript" src="js/flash_detect.v1.7.js"></script>
</head>
<body>
<div class="main">
  <div class="header">
    <div class="rss"><a href="index.html"><img src="images/logomain.png" width="218" border="0" /></a></div>
    <div class="search">
      <form id="form1" name="form1" method="post" action="">
        <span>
        <input name="q" type="text" class="keywords" id="textfield" maxlength="50" value="Search..." />
        </span>
        <input name="b" type="image" src="images/search.gif" class="button" />
      </form>
    </div>
    <div class="clr"></div>
    <div class="menu">
      <div class="logo"><img src="images/logo.png" width="205" height="88" border="0" alt="logo" /></div>
      <ul>
        <li><a href="index.html"><span>Home</span></a></li>
        <li><a href="about.html" class="active"><span>About Us</span></a></li>
        <li><a href="inquiry.html"><span>Inquiry form</span></a></li>
        <li><a href="contact.html"><span>Contact Us</span></a></li>
      </ul>
      <div class="clr"></div>
    </div>
    <div class="clr"></div>
  </div>
  <div id="slider">
    <!-- start slideshow -->
    <div class="flash_slider">
    <script language="JavaScript" type="text/javascript">
    AC_FL_RunContent(
        'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
        'width', '100%',
        'height', '400',
        'src', 'piecemakerNoShadow',
        'quality', 'high',
        'pluginspage', 'http://www.adobe.com/go/getflashplayer_de',
        'align', 'middle',
        'play', 'true',
        'loop', 'true',
        'scale', 'noscale',
        'wmode', 'transparent',
        'devicefont', 'false',
        'id', 'piecemakerNoShadow',
        'bgcolor', '#ffffff',
        'name', 'piecemakerNoShadow',
        'menu', 'true',
        'allowFullScreen', 'false',
        'allowScriptAccess','sameDomain',
        'movie', 'piecemakerNoShadow',
        'salign', ''
        ); //end AC code
</script>
</div>
    <div class="clr"></div>
    <!-- end #slideshow -->
    <div class="click_blog">
      <div class="clr"></div></div>
  </div>
  <div class="clr"></div>
  <div class="body">
    <div class="body_resize">
      <div class="right">
        <h2>About Us<br /></h2>
          <div class="left"><a href="inquiry.html"><img src="images/online-order.png" border="0" /></a></div>
        <p>The creation ultra tec dates back to 2001. The company has significantly and speedly grown to its current stature. We firmly and sincerely believe in quality. We reliably cater to various industrial sectors. Our major focus revolnes around the following: -</p>
<div>
<ul>
<li><strong>Strapping Solutions</strong></li>
<li><strong>Strapping Tools</strong></li>
<li><strong>Gluing Tachnology</strong></li>
</ul>
<ul>
<li><strong>Labelling & Packaging Glues</strong></li>
<li><strong>Case Palletising</strong></li>
<li><strong>Metal Marking Solutions</strong></li>
</ul>
<ul>
<li><strong>Screen Printing Mesh</strong></li>
<li><strong>Screen Printing Blades</strong></li>
</ul>
</div><div class="clr"></div>
<br /><br /><br /><br />
        </div>
  </div>
  <div class="clr"></div>
</div>
<div class="footer">
   </div>
</div>
</body>
</html>

使用会话

如果设置了会话,则他已登录。当他注销时,销毁会话。

登录时设置会话:

session_start();
$_SESSION['username'] = $_POST['username'];

然后在限制页面上做这样的事情:

session_start();
if (!isset($_SESSION['username'])) {
  //redirect to where people who are not logged in should be.
} else {
  //access to the page.
}

您需要这样的东西:登录页面:

<?php 
session_start() ;
(Here you check login data .If this login data is ok set username on session)
$_SESSION['username']= $username;
?>

在用户页面上:

<?php
session_start();
if(isset($_SESSION['username'])){
echo "Hello ".$_SESSION['username'];
}
else
{
die("You don't have acces on this page");'
}
?>