2016-08-13 59 views
0

我正在學習如何使會議從here登錄面板。我完全理解它,但我想打開另一個文件,在該代碼中,當有人輸入正確的密碼+電子郵件時,它只會回顯You have entered valid use name and password如果代碼成功,如何在PHP中運行其他代碼?

如何使它,頁面上明確了一切,並打開一個代碼(I型)...

可能是這樣,當我登錄時,屏幕上的一切都將得到明確和圖像將打開。

+1

看看'頭()'手動'標題(「位置:another.php」);'頭還會做很多其他的事情,但是在Location參數中查找標題 – RiggsFolly

+0

如何更改同一頁面中的內容? –

+0

然後把一些不同的HTML如果登錄成功 – RiggsFolly

回答

-1

雅降溫那麼簡單,回聲線ie.'echo「您輸入的有效使用名和密碼」後,」,請使用此或只需更換線

header('Location: http://www.example.com/'); 

你可以使用任何鏈接或本地文件,在這個例子中鏈接的地方

+0

我想改變在同一頁面的內容 –

+0

使用Ajax的這個或jQuery的加載功能 –

+0

我認爲jQuery的加載將工作正常,容易 –

0

你可以做到這一點的登錄功能 添加一個變量來檢查,如果該用戶登錄或不

<?php 
     $msg = ''; 
     $logedin = false; 
     if (isset($_POST['login']) && !empty($_POST['username']) 
      && !empty($_POST['password'])) { 

      if ($_POST['username'] == 'tutorialspoint' && 
       $_POST['password'] == '1234') { 
       $_SESSION['valid'] = true; 
       $_SESSION['timeout'] = time(); 
       $_SESSION['username'] = 'tutorialspoint'; 

       //echo 'You have entered valid use name and password'; 
       $logedin = true; 
      }else { 
       $logedin = false; 
       $msg = 'Wrong username or password'; 
      } 
     } 
    ?> 

然後檢查,如果用戶登錄或不看你會顯示

<div class = "container"> 
    //if the user is NOT logged in 
    <? if($loggedin){ ?> 
    <form class = "form-signin" role = "form" 
     action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']); 
     ?>" method = "post"> 
     <h4 class = "form-signin-heading"><?php echo $msg; ?></h4> 
     <input type = "text" class = "form-control" 
      name = "username" placeholder = "username = tutorialspoint" 
      required autofocus></br> 
     <input type = "password" class = "form-control" 
      name = "password" placeholder = "password = 1234" required> 
     <button class = "btn btn-lg btn-primary btn-block" type = "submit" 
      name = "login">Login</button> 
    </form> 

    Click here to clean <a href = "logout.php" tite = "Logout">Session. 
    <? }else{ ?> 
     // if user logged in yout code goes here 
    <? } ?> 
    </div> 
相關問題