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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:02:11+00:00 2026-05-30T14:02:11+00:00

This time, I need your help in something related to php. My users script

  • 0

This time, I need your help in something related to php. My users script is not working as expected, it’s supposed to keep logged in 3 weeks but this just fails, after less than 60 minutes the session is destroyed and I need to login again, any suggestion?

My code:

<?php
if (!isset($_SESSION)) session_start(); 

mysql_connect("YOU", "DONT", "NEED") or die("database connection failed");
mysql_select_db("THIS!!!") or die("database selection failed");

$user = $_POST['username'];
$pass = $_POST['password'];
$remember = $_POST['remember'];

$token = $_POST['login-token'];
$error;

        if(isset($_SESSION['username'])) {
            $error = $error." :erlgd:";
        }
        if(empty($user)){
            $error = $error." :erusr:";
        }
        if(empty($pass)){
            $error = $error." :erpwd:";
        } else
        $password = md5($pass);

        if(empty($error)){
            $sql = "SELECT * FROM login_users WHERE username='$user' AND password='$password'";
            $result = mysql_query($sql);
            $count = mysql_num_rows($result);
            if($count == 0){
                $sql = "SELECT * FROM login_users WHERE email='$user' AND password='$password'";
                $result = mysql_query($sql);
                $count = mysql_num_rows($result);
                if($count == 0){
                    $error = $error.":erwrg:";
                }
            }

        }


    // Once everything's filled out


        // Just double check there are no errors first
        if($error == '') {
            while($row = mysql_fetch_array($result)) {
                $minutes = 10080;

                if($minutes == 0)
                    ini_set('sesion.cookie_lifetime', 0);
                else
                    ini_set('session.cookie_lifetime', 60 * $minutes);
                session_regenerate_id();

                $sql = "SELECT * FROM login_activate WHERE username='$user'";
                $count = mysql_num_rows(mysql_query($sql));
                if ($count > 0)
                    $_SESSION['activate'] = 1;
                else
                    $_SESSION['activate'] = 0;

                $_SESSION['restricted'] = $row['restricted'];
                $_SESSION['name'] = $row['name'];
                $user_level = unserialize($row['user_level']);
                $_SESSION['user_level'] = $user_level;
                $sql = "SELECT level_disabled FROM login_levels WHERE level_level = '$user_level'";
                $disRow =  mysql_fetch_array(mysql_query($sql));
                $_SESSION['level_disabled'] = $disRow['level_disabled'];

                if(!empty($remember)) {
                    ini_set('session.cookie_lifetime', 60*60*24*100); // Set to expire in 3 months & 10 days
                    session_regenerate_id();
}
                // And our magic happens here ! Let's sign them in
                $_SESSION['username'] = $row['username'];

                unset($_SESSION['token']);
                echo "success";
                // Redirect after it's all said and done

            }

        }else{
            echo "error:".$error;
        }



?>

Thanks!

PS: As additional data, this is a shared server.

  • 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-30T14:02:13+00:00Added an answer on May 30, 2026 at 2:02 pm

    Take a look at the session.gc_maxlifetime in /etc/php5/apache2/php.ini

    Either update it there, or try putting ini_set('session.gc_maxlifetime', 60*60*24*7*3); in your script at the top

    Increase that to something larger

    basically, this is how long the server waits before clearing session files

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

Sidebar

Related Questions

I really need your help with this. We are planning on developing a real-time
I again need help by you, this time I struggle with covariance, contravariance, delegates
I've got a reasonably simple query (this time) that I need ALL the results
Ok this time I decided to make a list using the STL. I need
This doesn't need to be a real time solution, but are there some log
I need to learn RegEx but don't have time to figure this out right
Easy question this time. I'm trying to test whether or not a string does
I apologize for a lengthy question, but I really need your help. As a
UPDATE: In trying to replicate this problem one more time to answer your questions
I have solved this with PHP by adding the 'time()' to the img src

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.