Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP删除我的所有浏览器cookie?_Php_Cookies_Logout - Fatal编程技术网

如何使用PHP删除我的所有浏览器cookie?

如何使用PHP删除我的所有浏览器cookie?,php,cookies,logout,Php,Cookies,Logout,我有两个在同一个域上运行的应用程序实例,它们位于 主文件夹/ 子文件夹/暂存/ 我正在/staging实例上测试一些代码。 当用户注销时,我希望完全清除她/他的所有cookie 登录和注销在同一个文件index.php中处理 要注销,用户必须单击一个链接,将其带到index.php?action=logout 我在这里遇到的问题是,当用户注销时,并不是所有的cookie都被删除。名为phone\u call\u timer的cookie将不会被删除,除非我再次刷新注销页面,即index.php?

我有两个在同一个域上运行的应用程序实例,它们位于

主文件夹/ 子文件夹/暂存/ 我正在/staging实例上测试一些代码。 当用户注销时,我希望完全清除她/他的所有cookie

登录和注销在同一个文件index.php中处理

要注销,用户必须单击一个链接,将其带到index.php?action=logout

我在这里遇到的问题是,当用户注销时,并不是所有的cookie都被删除。名为phone\u call\u timer的cookie将不会被删除,除非我再次刷新注销页面,即index.php?action=logout页面2次,这对我来说是没有意义的,但这就是我面临的问题!我不知道我的代码是否有问题,或者PHP5.5.12中是否有bug

所以,我第一次去index.php?action=logout注销,但是仍然会保存一个cookie。电话计时器

但是,当我刷新F5页面时,再次执行注销代码,cookie就会消失

为什么没有从第一次删除phone_call_timer cookie? 如何解决此问题

注意:如果我导航到index.php或任何其他url,cookie将永远不会消失

这是第一次注销后的屏幕截图,因为您可以看到phone_call_timer cookie仍然存在,但此时它应该已被删除。

这是我再次刷新注销页面后的屏幕截图,因为你可以看到电话计时器cookie现在不见了!

下面是我的PHP代码index.PHP文件的内容


它可能与此有关:如果$name=='phone\u call\u timer'&&$ref=='auto'{continue;}在某些条件下,它似乎跳过了特定的cookie-确保该条件没有在错误的时间干扰。即使我完全删除了该行,我也会遇到同样的问题。那我猜不是这样的值得一试。我也有同样的问题,我试过这个:,但它对我不起作用,现在我正在寻找一种方法,用javascript删除它,我认为是的better@JefferyThaGintoki谢谢你的意见。如果你正在寻找一个使用jQuery的解决方案,试试这个,我一直在使用它,效果非常好
<?php

    require 'requires/APP_configuration.php';
    require 'requires/PHP_generic_functions.php';

    require 'classes/Connection.php';
    require 'classes/Session_Manager.php';

    //define this page name
    define('pageTitle' , SYSTEM_NAME . " - Sign In");
    define('pageDescription', "Sign In");
    define('pageKeywords', "Sign In");

    define('ADD_GLOBAL_META_TAGS', '
        <script type="text/javascript" src="js/captcha/jquery.captcha.js"></script>
        <link type="text/css" href="js/captcha/captcha.css" rel="stylesheet">
        ');



    $session = new \classes\Session_Manager(SESSION_NAME, SESSION_MAX_AVAILABLE, SESSION_SAVE_PATH, SESSION_SAVE_URL, SESSION_HTTPS_ONLY);
    $ref = "none";
    $newURL = 'index_bridge.php';
    $redirectTo = '';
    $newURLAfterRefresh = 'index.php';
    $action = '';
    $loggedOut = 0;

    if(      isset($_GET['ref']) 
        && ! empty($_GET['ref']) ){
        $ref = $_GET['ref'];
    }



    if( isset($_GET['redirectTo']) && !empty($_GET['redirectTo']) ){
        $redirectTo = $_GET['redirectTo'];
        $newURL = $redirectTo;
    }
    if(!empty($redirectTo)){
        $newURLAfterRefresh = 'index.php?ref=' . $ref . '&redirectTo=' . $redirectTo;
    }

    $newURLshort = $newURL;
    if(strpos($newURL, '?') !== false){
        $newURLshort = substr($newURL, 0, strpos($newURL, '?') );
    }

    $file_found = file_exists($_SERVER['DOCUMENT_ROOT'] . $newURLshort);

    if(!$file_found){   
        $newURL = 'index_bridge.php';
    }



    /********** START CODE **********/
    //BEGIN current page's code

    if(isset($_GET['action'])){
        $action = $_GET['action'];
    }

    if(empty($action)){
        $session->resumeSession();

        if( $session->isAutherized() === true ){
            header('Location: index_bridge.php');
            exit();
        }   
    }

    if($action == 'logout' ){

        $cookies = array();
        $var = str_replace('/','', SESSION_SAVE_PATH);
        if (isset($_SERVER['HTTP_COOKIE'])) {
            $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
        }

        $session->destroy();    
        foreach($cookies as $cookie) {

            $parts = explode('=', $cookie);
            $name = trim($parts[0]);

            if($name == 'phone_call_timer' && $ref == 'auto'){
                continue;
            }

            setcookie($name, null, time()-MAX_STORE_COOKIE);
            setcookie($name, null, time()-MAX_STORE_COOKIE, '/');
            setcookie($name, null, time()-MAX_STORE_COOKIE, $var);
            setcookie($name, null, time()-MAX_STORE_COOKIE, SESSION_SAVE_PATH);

            unset($_COOKIE[$name]); 
        }

        $loggedOut = 1; 
    }


/**********************************************************
********************* START OUTPUT ************************
**********************************************************/
    //This should always be the first output
    include 'includes/meta.php';
    ?>
<script>
$(function(){

    $('#user_field,#password_field').keydown(function (e){
        if(e.keyCode == 13)
            $('#sign_in').click();

    });

    $('#sign_in').on('click', function(e){

        e.preventDefault();
        $(this).html('Please wait...');

        if ($(this).prop("disabled"))
            return false;

        $(this).prop("disabled", true);

            $('#respond').removeClass('bg-danger').text('');
            $.ajax({    
                type: 'POST',
                url: 'ajax/handler-sign-in.php',        
                data: $('#signinForm').serialize(),
                dataType: 'json',
                cache: false,
                timeout: 10000,
                success: function(data) { 

                    if(!data)
                        return;


                    if(data.success == true)                    
                        window.location.href = '<?php echo $newURL ?>';                 
                    else {
                        $('#respond').addClass('bg-danger').text(data.msg);
                        $('#sign_in').prop("disabled", false);
                        $('#sign_in').html('Sign In');

                        if(data.human_check_required == 1)
                            $("#humachCheck").show();
                        else 
                            $("#humachCheck").hide();

                    }

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    $('#responseAddForm').removeClass().addClass('errorBox').html('<p>There was an<strong> ' + errorThrown + '</strong> error due to a<strong> ' + textStatus + '</strong> condition.</p>').fadeIn('fast');         
                }
            });
    });

    $("#humachCheck").captcha({
        captchaDir: "js/captcha",
        formId: "signinForm",
        url: "ajax/set-correct-captcha.php"
    });

});
</script>

<?php




    //Display the activity table
     echo '<div>';
     echo '<div class="Body">';

        if($loggedOut){
            echo '<div class="passBox"><p style="text-align: center;">You have successfully logged out<br><a href="'.$newURLAfterRefresh.'">Click Here</a> to login.</p></div>';

        } else {

            //login form
            echo '  <div style="width: 350px; margin: 0 auto;">
                        <div class="account-wall">
                            <img class="profile-system-logo" src="images/accordiLogoX200.png" alt="Logo">
                            <h1 class="text-center login-title">Sign in to continue to '.SYSTEM_NAME.'</h1>
                            <div id="respond" class="margin-lg-around center-block padding-md-around"></div>
                            <form class="form-signin" id="signinForm" method="post">
                            <input type="text" class="form-control" name="username" id="user_field" placeholder="User Name" required autofocus="autofocus">
                            <input type="password" class="form-control" id="password_field" name="password" placeholder="Password" required>
                            <div id="humachCheck" class="box-hidden" style="margin: 10px 0;">You must enable javaScript in order to use this system</div>
                            <div class="btn btn-lg btn-primary btn-block" id="sign_in">Sign in</div>
                            </form>
                        </div>
                    </div>';


        }


    //close Body DIV
    echo '</div>';





include 'includes/menu_master_bottom.php';
include 'includes/footer.php';



/**********************************************************
********************* END OUTPUT ************************
**********************************************************/

/********** END CODE **********/


?>