普通网友 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条)

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan