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 6050583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:42:16+00:00 2026-05-23T07:42:16+00:00

This is a question regarding an old one of mine: cookie won’t unset: cookie

  • 0

This is a question regarding an old one of mine: cookie won’t unset:
cookie wont unset
where I had problems unseting the cookie (but it was set ‘properly’),

Now that the problem is solved; the cookie doesn’t seem to SET

cookie ‘set’: (does not work)

setcookie("id",$data['id'], time()+3600*24*30,'/');
setcookie("alias",$data['nombre'], time()+3600*24*30,'/');

cookie check: (seems to work)

    function sesion(){

    if(isset($_COOKIE['id']) && isset($_COOKIE['alias'])){
                    $_SESSION['logueado'] = true;
                    $_SESSION['id'] = $_COOKIE['id'];
                    $_SESSION['alias'] = $_COOKIE['alias'];

                    return true;  //THIS IS NEVER RETURNING TRUE
                }
if(isset($_SESSION['id']) && isset($_SESSION['logueado']) && $_SESSION['logueado'] == true){

                    return true;
                }
                 else{ return false;
    }



    }

cookie unset: (works)

function cerrar_sesion(){
  session_start();
  $_SESSION['logueado']= false;
  $_SESSION['id']= NULL;
  session_unset();
  session_destroy();
  setcookie("id",false,time()-3600,"/");
  setcookie("alias",false,time()-3600,"/");
  unset($_COOKIE['id']);
  unset($_COOKIE['alias']);
}

What happens is that login is working only through $_SESSION so after 30 minutes of no activity the user is no longer logged in,

Any idea what I’m doing wrong? Thanks a lot!

  • 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-05-23T07:42:17+00:00Added an answer on May 23, 2026 at 7:42 am

    set cookie lines work fine with me.

    as for }else if(isset($_COOKIE['id']) && i
    since you return if you remove the else here is still okay, if there was no return above you would have to keep the else here in order not to evaluate this block
    generally speaking I am not sure that elseif is the same with else if in all cases

    The way the function session is build will act like this:

    • On the first load it will show: no cookie, no session because you cannot see a cookie until reload (which I guess you already know).
      -On second load you will see cookie alive session set.
      -after the second load you always see session is set.

    All I want to say that session works exactly as expected to work, so I don’t really see any problem.

    <?php
    
    $data='Hello'; 
    setcookie("id",$data['id'], time()+3600*24*30,'/');
    setcookie("alias",$data['nombre'], time()+3600*24*30,'/');
    
    session_start(); 
    
    function sesion()
         {
    
            if(isset($_SESSION['id']) && isset($_SESSION['logueado']) 
                && $_SESSION['logueado'] == true)
            {
                echo 'SESSION IS SET<br>';
                return true;
            } 
            if(isset($_COOKIE['id']) && isset($_COOKIE['alias']))
            {
                $_SESSION['logueado'] = true;
                $_SESSION['id'] = $_COOKIE['id'];
                $_SESSION['alias'] = $_COOKIE['alias'];
                echo 'COOKIE is alive and session set'.$_SESSION['alias'].'<br>';
                return true;  //THIS IS NEVER RETURNING TRUE
             }
            else
            {  
                echo 'NO SESSION,   NO COOKIE YET, WAIT UNTIL REFRESH<br>';
                return false;
            } 
    } 
     sesion() ; 
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a question regarding this matter some days ago, but I'm still wondering
There are many question regarding this topic but there is no clear answer. Although
I have a case similar to this MySQL question regarding the IN clause, but
My python env is 2.7 I know this is an old question, but I've
Yesterday I posted this question regarding using lambdas inside of a Join() method to
Yesterday, I asked this question regarding best practices for a simple information retrieval system
This question is regarding getopt function in php. I need to pass two parameter
This is a question regarding the timezone specified in the Expires and Last-Modified HTTP
Again I have a question regarding this plugin: http://t.wits.sg/2008/06/20/jquery-progress-bar-11/ What I want to achieve
This question is related to database/RDBMS where i have little knowledge regarding performance and

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.