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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:09:20+00:00 2026-06-08T17:09:20+00:00

so, I am struggling for 1 week now on this PHP code and still

  • 0

so, I am struggling for 1 week now on this PHP code and still can’t get it working. I need a cookie to be set for a user for 1 year, and also when he close his browser and visit our site again later, not to have to log in again. If someone can write the code as it should be set on my file I would be very grateful. My original code is bellow, it’s from my config.php file.
Many thanks in advance!

function create_slrememberme() {
        $key = md5(uniqid(rand(), true));
        global $conn;
        $sql="update members set remember_me_time='".date('Y-m-d H:i:s')."', remember_me_key='".$key."' WHERE username='".mysql_real_escape_string($_SESSION[USERNAME])."'";
        $conn->execute($sql);
        setcookie('slrememberme', gzcompress(serialize(array($_SESSION[USERNAME], $key)), 9), time()+60*60*24*30);
}

function destroy_slrememberme($username) {
        if (strlen($username) > 0) {
                global $conn;
                $sql="update members set remember_me_time=NULL, remember_me_key=NULL WHERE username='".mysql_real_escape_string($username)."'";
                $conn->execute($sql);
        }
        setcookie ("slrememberme", "", time() - 3600);
}

if (!isset($_SESSION["USERNAME"]) && isset($_COOKIE['slrememberme'])) 
{
        $sql="update members set remember_me_time=NULL and remember_me_key=NULL WHERE remember_me_time<'".date('Y-m-d H:i:s', mktime(0, 0, 0, date("m")-1, date("d"),   date("Y")))."'";
        $conn->execute($sql);
        list($username, $key) = @unserialize(gzuncompress(stripslashes($_COOKIE['slrememberme'])));
        if (strlen($username) > 0 && strlen($key) > 0)
        {
            $sql="SELECT status,USERID,email,username,verified from members WHERE username='".mysql_real_escape_string($username)."' and remember_me_key='".mysql_real_escape_string($key)."'";
            $rs=$conn->execute($sql);
            if($rs->recordcount()<1)
            {
                $error = "Error: Could not locate your account.";
            }
            elseif($rs->fields['status'] == "0")
            {
                $error = "Error: Your account has been disabled by the administrator.";
            }
            if($error=="")
            {               
                $_SESSION['USERID']=$rs->fields['USERID'];
                $_SESSION['EMAIL']=$rs->fields['email'];
                $_SESSION['USERNAME']=$rs->fields['username'];
                $_SESSION['VERIFIED']=$rs->fields['verified'];
                create_slrememberme();
            }
            else
            {
                destroy_slrememberme($username);
            }
        }
}
  • 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-08T17:09:21+00:00Added an answer on June 8, 2026 at 5:09 pm

    This line:-

    setcookie ("slrememberme", "", time() - 3600);
    

    is setting your cookie to expire in the past, i.e. it is already expired!

    To set it for a year you need to do:-

    setcookie("slrememberme", "", time()+60*60*24*30*365);
    

    will set it for approximately 1 year.

    See the manual for more details.

    Also, this line:-

    if (!isset($_SESSION["USERNAME"]) && isset($_COOKIE['slrememberme']))
    

    Should be:-

    if (isset($_SESSION["USERNAME"]) && isset($_COOKIE['slrememberme']))
    

    You probably need to set the cookie-expiry function located in your php.ini file named session.cookie_lifetime. You should set it to be 31536000, this will make it expire after 1 year, it is probably set to 0.

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

Sidebar

Related Questions

I have been struggling with this issue for one week, and still far away
I've been struggling with this for the past week and can't find a single
Struggling to get this query working: $query_search = SELECT questionnaires_index.id, questionnaires_index.ea_num, questionnaires_index.address, questionnaires_index.status, questionnaires_index.json_stored
I've been struggling on this thing for a week without being able to find
I've been struggling for a week now trying to figure out how to generate
I was struggling for past one week to do obfuscate with android application can
Struggling to get my head around these MD Arrays so hoping someone can help.
Struggling to get nested repeaters working although I feel I am close! I am
Struggling with this problem for an hour now and searched both stackoverflow and google
I started using NHibernate this week (struggling). I have a small application with 3

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.