1

PHPログアウトスクリプトを作成しようとしていますが、実装するとすぐに、ログイン後にページがページにリダイレクトされます。コードは次のとおりです。

Connect.php

<?php 
    session_start();
    $link = mysql_connect("localhost", "database_name", "database_pass") or die(mysql_error());
    mysql_select_db("database_name") or die(mysql_error());

    if(isset($_COOKIE['username'])) 
             $_SESSION['username'] = $_COOKIE['username'];
 ?>  

Logout.php

<?php
    include("connect.php");
    session_start();
    session_destroy();
    $username = $_SESSION['username'];
setcookie($username, time()-3600);  
    header("Location: index.php");
    die;    
?> //immediately after here, instead of going to index.php(the login page), it goes straight to the page that would appear after if the user had logged in(control_panel.php). 

何か案は?ありがとう!

4

2 に答える 2

2

このページをご覧ください: http://blog.ircmaxell.com/2011/08/security-review-creating-secure-php.html

「安全な PHP ログイン スクリプトの作成」を完全に実行します。現在のソリューションには、多くのセキュリティ上の問題があります。

于 2012-07-23T06:02:53.557 に答える
1

あなたのコードは間違っていると思います.問題はここにあります..

logout.php では、セッションの設定を解除した後に Cookie の有効期限が切れていますが、Cookie の有効期限が切れていません。

そして connect.php では、この条件を使用してセッションを再度設定していますが、Cookie がまだユーザーのブラウザにあるため設定されています

if(isset($_COOKIE['username'])) 
            $_SESSION['username'] = $_COOKIE['username'];

したがって、これを行う代わりに:

setcookie($username, time()-3600);

これを行う :

 setcookie($username, "", time()-3600);
于 2012-07-23T06:07:23.533 に答える