doutuo7815
2013-12-20 01:08
浏览 30
已采纳

如何为已登录的用户禁用登录页面[关闭]

How I can disable login page for users who logged in already? I tried a lot to writing php code for "if user logged in already can't logged in again and can't see login page" but I didn't know

<?php
    session_start(); 

    if(isset($_SESSION['user_name'])) 
    { 
        header('Location: home.php'); 
        exit;
    }
?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsfds4551 2013-12-20 01:15
    已采纳

    You should take a look at this post: Using sessions & session variables in a PHP Login Script. Here you can see how to use php session for the same use case!

    点赞 评论
  • dongpan1365 2013-12-20 01:15

    create session .if session set then redirect to page in the header location

    <?php  
    
      session_start();  // needed for sessions.
        if(isset($_SESSION['url'])) 
           $url = $_SESSION['url']; // holds url for last page visited.
        else 
           $url = "index.php"; // default page for 
    
        header("Location: http://example.com/$url");//redirect page you want
    
    点赞 评论

相关推荐 更多相似问题