Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //这个PHP脚本的目的是将数据库中的数据全部读出,然后写到页面上,在访问该页面前需要输入密码。
- //以DATABASE开头的大写部分为需要按照实际情况修改的部分。
- //密码部分的代码来自: http://www.goldapple.name/?action=show&id=737
- <?php
- $password = "PASSWORD"; // 这里是设置访问密码
- $p = "";
- if(isset($_COOKIE["isview"]) and $_COOKIE["isview"] == $password){
- $isview = true;
- }else{
- if(isset($_POST["pwd"])){
- if($_POST["pwd"] == $password){
- setcookie("isview",$_POST["pwd"],time()+3600*3);
- $isview = true;
- }else{
- $p = (empty($_POST["pwd"])) ? "需要密码才能查看,请输入密码。" : "密码不正确,请重新输入。";
- }
- }else{
- $isview = false;
- $p = "内部资料,请联系Chris获取密码。";
- }
- }
- if($isview){ ?>
- <?php
- //建立数据库链接,
- mysql_connect("localhost", "DATABASEUSERNAME", "DATABASEPASSWORD") or
- die("Could not connect: " . mysql_error());
- //选择数据库
- mysql_select_db("DATABASENAME");
- //查询sql语句
- $result = mysql_query("SELECT `DATATIME`, `NAME`, `CONAME`, `EMAIL`, `PHONE`, `SAMESOFT` FROM `DATABASENAME`.`DATABASETABLENAME`");
- //输出查询结果
- echo '
- <!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=utf-8" />
- <title>读取数据库</title>
- </head>
- <body>
- <table width="1020" border="1">
- ';
- echo "<tr><td>时间</td><td>姓名</td><td>公司名</td><td>电子邮件</td><td>电话</td><td>备注</td></tr>";
- while ($row = mysql_fetch_array($result)) {
- echo "<tr>";
- echo "<td>",strip_tags($row['DATATIME']) ,"</td>";
- echo "<td>",strip_tags($row['NAME']) ,"</td>";
- echo "<td>",strip_tags($row['CONAME']) ,"</td>";
- echo "<td>",strip_tags($row['EMAIL']) ,"</td>";
- echo "<td>",strip_tags($row['PHONE']) ,"</td>";
- echo "<td>",strip_tags($row['SAMESOFT']) ,"</td>";
- echo "</tr>";
- }
- echo "
- </table>
- </body>
- </html>
- ";
- //释放结果内存
- mysql_free_result($result);
- ?>
- <?php }else{ ?>
- <!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=utf-8" />
- <meta http-equiv="pragma" content="no-cache" />
- <meta http-equiv="cache-control" content="no-cache" />
- <meta http-equiv="expires" content="0" />
- <title>查看</title>
- <!--[if lt IE 6]>
- <style type="text/css">
- .z3_ie_fix{
- float:left;
- }
- </style>
- <![endif]-->
- <style type="text/css">
- <!--
- body{
- background:none;
- }
- .passport{
- border:1px solid red;
- background-color:#FFFFCC;
- width:400px;
- height:100px;
- position:absolute;
- left:49.9%;
- top:49.9%;
- margin-left:-200px;
- margin-top:-55px;
- font-size:14px;
- text-align:center;
- line-height:30px;
- color:#746A6A;
- }
- -->
- </style>
- <div class="passport">
- <div style="padding-top:20px;">
- <form action="?yes" method="post" style="margin:0px;">输入查看密码
- <input type="password" name="pwd" /> <input type="submit" value="查看" />
- </form>
- <?php echo $p; ?>
- </div>
- </div>
- <?php } ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement