普通网友 2011-01-03 18:55
浏览 38
已采纳

使用session隐藏php中的表

how can i hide the following table in php using session. (i dont want the logged in user to see the login table again instead of it i want to show that user's information there til the session is alive)how can i do this please help me friend.

<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF" class="post">
<tr>
<td colspan="3"><h2><strong>Member Login </strong></h2></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername" maxlength="65"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword" maxlength="65"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>

and coding for that "checklogin.php" is as follows

<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="123"; // Mysql password
$db_name="test"; // Database name
$tbl_name="member"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");

echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('you have logged in successfully')</SCRIPT>");
echo("<SCRIPT LANGUAGE='JavaScript'>window.location = 'main_login.php'</SCRIPT>");

//header("location:login_success.php");
//window.location = 'login_success.php'
//echo "<script>navigate('login_success.php')</script>";
//exit();

}
else {
echo "Wrong Username or Password";
include 'main_login.php';
}

ob_end_flush();
?>
  • 写回答

3条回答 默认 最新

  • drxkx6149 2011-01-03 19:00
    关注

    you should set a session variable after login. and then check it before printing table.

    <?php
    session_start(); 
    
    if (isset($_SESSION['loged']) && ($_SESSION['loged'] == false))
    {
       ?>
       <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"     class="post">
       <tr>
       <td colspan="3"><h2><strong>Member Login </strong></h2></td>
       </tr>
       ....
       ...
       </table>
       <?php
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?