使用会话变量处理多个选项卡会话

时间:2014-10-16 16:02:12

标签: php html session

嘿伙计们,我的工作人员要求我将这项练习作为课程的一部分。所以练习的全部内容是拥有一个名为index.php的登录页面,并为其提供登录表单。现在我被要求做的就是使用会话变量作为我的控制变量。如果说我在浏览器中打开一个新标签并访问同一个文件,那么我应该获得登录成功页面而不是登录表单。登录成功页面包含一个注销按钮,点击后该变量将被取消设置。简单来说,我可以告诉你:

if session!=''
show success
else
show form

这是我的代码:

<html>
<head>
<title>Login Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
session_start();
$link = mysqli_connect('localhost', 'root', '');
$db_selected = mysqli_select_db($link,'tpf');
if(isset($_POST['login']))
    {
    $_SESSION['id']=$_POST['id'];
    $_SESSION['pass']=$_POST['pass'];
    date_default_timezone_set('Asia/Calcutta');
    $date = date('Y-m-d H:i:s');
    $id = $_SESSION['id'];
    $pass = $_SESSION['pass'];
    $in=mysqli_query($link,"SELECT * from login where id='$id' and password='$pass'");
    $count=mysqli_num_rows($in);
    if($count==1)
    {
    $sql2="SELECT * FROM login WHERE id='$id'";
    $result = mysqli_query($link,$sql2);
    $row = mysqli_fetch_array($result);
    $person=$row['name'];
    $no=$row['id'];
    $last=$row['time'];
    if($last=='')
    {
    $last="first login";
    }
    $up=mysqli_query($link,"UPDATE Login SET `time`='$date' where id='$id'");
    echo "<div class='login'><form method='post' action=''>";
    echo "<center>ID : $no <br><br> Name : $person <br><br> Last Login : $last <br>";
    echo "<p><input type='submit' name='back' value='back'></p></center></form></div>";
    }
    }
    else
    {
    echo "<div class='login'><form method='post' action=''>";
    echo "<h1>EMPLOYEE LOGIN</h1><p><font size='2'>Login &nbsp ID:</font> <input type='text' name='id' id='id' placeholder='Login ID'></p>";
    echo "<p><font size='2'>Password:</font> <input type='password' name='pass' id='pass' placeholder='Password'></p>";
    echo "<p class='submit'><input type='submit' name='login' value='login'></p></form>";
    echo "<form method='post' action='register.php'>";
    echo "<p class='submit'><font size='2'>New User? &nbsp </font><input type='submit' name='change' value='sign up'></p></form></div>";
    }
mysqli_close($link);
?>
</body>
</html>

0 个答案:

没有答案