2017-08-31 106 views
0

我的代碼將不會重定向到我的重定向 功能的網站。正確登錄時,模態登錄只會消失。這不是一個WordPress網站。我們將此作爲測試頁面用於我們的客戶的登錄頁面。這裏 是代碼(請原諒長碼):php modal登錄重定向到另一個網站

<?php 
session_start(); 

$userinfo = array(
       'user1'=>'password1', 
       'user2'=>'password2' 
       ); 

if(isset($_GET['logout'])) { 
    $_SESSION['username'] = ''; 
    header('Location: http://www.espn.com'); 
} 

function redirect() { 
    $_SESSION['username'] = ''; 
    header('Location: http://www.mgoblue.com'); 
    exit(); 
} 

if(isset($_POST['username'])) { 
    if($userinfo[$_POST['username']] == $_POST['password']) { 
     $_SESSION['username'] = $_POST['username']; 
    }else { 
     //Invalid Login 
    } 
} 
?> 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Document</title> 

</head> 
<body> 
    <!-- Button to open the modal login form --> 
    <button onclick="document.getElementById('id01').style.display='block'">Login</button> 

    <!-- The Modal --> 
    <div id="id01" class="modal"> 
     <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span> 

     <?php if((isset($_SESSION['uname']))): ?> 
      <!--<p>You are logged in as <?=$_SESSION['username']?></p>--> 
      <!--<p><a href="?logout=1">Click to site</a></p>--> 
      <?php redirect(); ?> 
     <?php else: ?> 

     <!-- Modal Content --> 
     <form name="login" class="modal-content animate" action="" method="post"> 
      <!-- No Avatar!!! --> 

      <!-- Login Info --> 
      <div class="container"> 
       <label><b>Username</b></label> 
       <input type="text" placeholder="Enter Username" name="username" required><br /><br /> 

       <label><b>Password</b></label> 
       <input type="text" placeholder="Enter Password" name="password" required><br /><br /> 
       <button type="submit">Login</button>     

      </div> 

      <div class="container" style="background-color:#f1f1f1">     
       <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button> 
      </div> 
     </form> 
     <?php endif; ?> 
    </div>  
</body> 
</html> 

我是什麼代碼丟失,比其他的CSS?

+0

這是CSS代碼: – VDOGamer

+0

<?php if((isset($ _ SESSION ['uname']))):?>這是拼寫錯誤嗎?它不應該是'用戶名'嗎? – Chiperific

回答

1

在您的代碼中,您正在使用$ _SESSION ['username']向上,然後檢查下面的$ _SESSION ['uname'],這從未設置,可能是您的問題。

這只是一個附註,但我通常會在位置標題前添加重定向代碼,如下所示: header('HTTP/1.1 302 Found'); header('Location:'。$ uri);