我必须在登录页面和个人资料页面中使用会话

时间:2018-04-12 10:43:43

标签: html sql-server iis

我有一个index.php

<?php
 SESSION_START();

    if ( $_SESSION['loggedin'] == true) {



           Profile page content.......



    }
    else{
          $_SESSION['loggedin'] == false;
          header('Location:/login.php');    
     }

我有login.php

<?php
  SESSION_START();
 ?>
 <!doctype html>
 <html>
 <base href="/"> 
 <body style="background-color: #f1f1f1;">
    <form  name="myForm"  method="post" action="logincheck.php">
     userid<input type="text"name="usename">
     <br>password<input typy="password" name="password">
      <br>
     <input type="submit"name="submit"value="login">
   </form>
 </body>
</html>

我有Logincheck.php

     <?php  
      SESSION_START();
      $uname = $_POST['username'];                                                                                      
      $pword = $_POST['password'];
      $serverName = "ipaddress,portnumber";                                                                                 
        $connectionInfo = array( "Database"=>"testing", 
                              "UID"=>"username","PWD"=>"password");
        $conn = sqlsrv_connect( $serverName, $connectionInfo);
         if( $conn )  
        {   
            $params = array($uname, $pword);                    
            $sqlquery="select username from emp where username=? and 
                         password=?";

            $query = sqlsrv_query($conn,$sqlquery,$params);

            $count=sqlsrv_has_rows($query);     

            if ($count ===false )
                {
                    $_SESSION['error']=true;
                    header('Location:/login.php');                                                                              

                }
                else
                {   $_SESSION['loggedin'] = true;
                    $_SESSION['user']=$_POST['username'];   
                     header("Location: /index.php?$uname");                                                                     

                }  
               sqlsrv_close($con);                                                                                          

        }else{
            echo"<h1 >Database Connection Error...</h1>";                                                               
        }
   ?>

除了index.php之外,我没有遇到任何问题。因为这不会重定向到任何页面,这会显示错误,如

此页面无效 localhost目前无法处理此请求。 HTTP ERROR 500

我没有得到解决方案。 任何人都可以解决这个问题。

0 个答案:

没有答案