Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8363371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:09:37+00:00 2026-06-09T12:09:37+00:00

I use the PHP Session variable to have a user login and edit their

  • 0

I use the PHP Session variable to have a user login and edit their website. When they logout I call the session_destroy(); function to terminate the session.

At the login screen, I have an option to ‘remember this computer’ and instead of using a $_SESSION[] variable I set a cookie like this:

setcookie("admin", true, $expire);

The cookie is set, but when I logout, the cookie unsets. Any way to prevent this? I want the session to end, but I would like the website to remember the computer as well.

Thank you for your time.

Edit: Here are the two methods I use to initiate and destroy the sessions (the session methods I call are on another class)

 public function loginCheck() {

    //check if the remember me is set

    if (isset($_POST['remember'])) {
        $expire = time() + 60 * 60 * 24 * 30;
        setcookie("admin", true, $expire);
    }
    else{
        setcookie("admin", "", time()-3600);
    }


    $sth = $this->db->prepare("SELECT uid FROM philllwareusers WHERE 
            usr = :login AND pasw = :password");

    $sth->execute(array(
        ':login' => $_POST['user'],
        ':password' => $_POST['pswrd']
    ));

    $data = $sth->fetch();

    $count = $sth->rowCount();

    if ($count > 0) {

        //check if user has permision to edit this website

        $sth = $this->db->prepare("SELECT web_id FROM website_spine WHERE 
            admin_id = :uid ");
        $sth->execute(array(
            ':uid' => $data['uid']
        ));

        $datas = $sth->fetch();

        $counts = $sth->rowCount();
        if ($counts > 0) {

            if ($datas['web_id'] == WEB_ID) {



                Session::init();
                Session::set('uid', $data['uid']);
                Session::set('loggedIn', true);
                header('location: ../index');
            } else {
                header('location: ../Adminlogisn');
            }
        }

        // login
    } else {
        header('location: ../Adminlogin');
    }
}

function logout() {
    Session::init();
    Session::destroy();
    header('location: '.URL.'/Adminlogin');
}

this is what the admin login looks like (the part that will check if the cookie should be set, and should stay set or destroy it.),

 <?php
        if(!isset($_COOKIE['admin']) || $_COOKIE['admin'] == ''){?>
    Remember this computer as an admin computer <div style="display: inline;cursor: pointer;" onclick="alert('By selecting this option, your website will remember this computer and present the login option on the menu bar when you are not logged in.')">[?]</div>
    <input type="checkbox" name="remember" style="width: 20px;"/> 
    <?php

    }
    else{
        ?>
          Un-check  to forget this computer as an admin computer. <div style="display: inline;cursor: pointer;" onclick="alert('This computer is currently rememberd as and admin computer, making the login link on the menu bar visible for easy access. Uncheck this box to forget this computer as admin computer.')">[?]</div>
    <input type="checkbox" name="remember" checked="checked" style="width: 20px;"/>
    <?php
    }
    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:09:38+00:00Added an answer on June 9, 2026 at 12:09 pm

    here is the link in which you can find the answer of your question:

    http://www.codeflask.com/2012/08/why-session-destroy-when-remove-my.html

    And the actual answer (cited from the link) is:

    Session is destroyed automatically when cookies removed the reason is whenever the session is created it also stores its id in a cookie so that’s why session destroyed automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use PHP session without using cookies. I have enabled session.use_trans_sid
Possible Duplicate: Troubles with a PHP session variable after form submission I use sessions
When is it best to use database as a session store in PHP? I
I use php with ajax. <?php /* * Suppose, user has entered both correct
I have an object, based on the Singleton design, that I use for user
I am making a simple Dynamic Website using PHP, where i allow the user
I have PHP application for offers. In this application when user log in I
I have a problem regarding assign session variable to class variable while initialize the
i have a user login system which works off of sessions such that when
I have an index.php with the following content: include_once('includes/auth.php'); include_once('classes/class.DatabaseQuery.php'); include_once('classes/class.Project.php'); include_once('classes/class.User.php'); $project =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.