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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:08:06+00:00 2026-06-14T11:08:06+00:00

My current login script I made with PHP Is working, But when i try

  • 0

My current login script I made with PHP Is working, But when i try to login and uncheck “Remember me” It logs in, But does not set the required cookies, However, If i check the Remember box, It logs in and sets the cookies.
So the issue is, What causes it to happend?
My PHP CODE:

<?php
    /* Mysql data */
    $MysqlUsername = "root";
    $MysqlPassword = "";
    $MysqlHostname = "localhost";
    $MysqlDatabase = "teamgamersnet";
    $Salt = "TGN2012";
    $Username = $_POST['Username'];
    $Password = $_POST['Password'];
    $Remember = $_POST['Remember'];
    $Cookie = "TGN";
    $IP       = $_SERVER['REMOTE_ADDR'];
    if (empty($Username) || empty($Password)) { die("Please fill in all the fields"); }


    $hash = hash('sha256',strtolower($Username).$Password.$Salt);

    $Sql = new mysqli($MysqlHostname, $MysqlUsername, $MysqlPassword, $MysqlDatabase);
    if ($Sql->connect_error){ echo $Sql->connect_error; }
    $sUser = $Sql->real_escape_string($Username);
    $sPass = $Sql->real_escape_string($Password);
    $xPass = $Sql->real_escape_string($hash);


    $CheckUser = $Sql->query("SELECT * FROM `users` WHERE `Username` = '".$sUser."'");;
    if ($CheckUser->num_rows == 0) { header("Location: /?p=Login&wrongusr=true"); die(); }
    $xCheckUser = $CheckUser->fetch_array(MYSQLI_ASSOC);
    if ($xCheckUser['Activated'] == "false") { header("Location: /?p=Login&activate=true"); die(); }
    if(strtolower($Username) == strtolower($xCheckUser['Username'])) {
        if($hash == $xCheckUser['Password']) { // Check if password is correct
        if(isset($Remember)){ // Set a looong cooke to remember
                setcookie ($Cookie."User", htmlspecialchars($Username), time() + 99999999);
                setcookie ($Cookie."Pass", $hash, time() + 99999999);
                        header("Location: /?login=true");

        }
        else
        { // Set a standard cookie
                setcookie ($Cookie."User", htmlspecialchars($Username), time() + 3600);
                setcookie ($Cookie."Pass", $hash, time() + 3600);
                header("Location: /?login=true");
        }

    }

    else
    {
        header("Location: /?p=Login&wrongpwd=true"); // Send them to home page 
    }
    }
?>
  • 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-14T11:08:08+00:00Added an answer on June 14, 2026 at 11:08 am

    The answer to your question is not due to PHP itself, but (I think) down to your webserver. A bit of information about cookies and how they are set:
    – They are based on a timestamp – more importantly, a timestamp set by the server!
    – They will automatically expire based on the said timestamp.

    I’d strongly suggest looking closely at the HTTP headers that are being sent by the server and checking the expiration date, as I was not able to reproduce your bug locally, but have had similar in production before.
    Go on your page, uncheck remember me, and check headers sent to you by the server. You’ll find something like this:
    Set-Cookie:TGNPass=some hash; expires=Sat, 17-Nov-2012 22:27:44 GMT

    The expiration date/time is what you are after. Check that it is what you are expecting (i.e. one hour from now), and if not, you’ll need to adjust your server’s timezone settings. This is easily done using http://php.net/manual/en/function.date-default-timezone-set.php .

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

Sidebar

Related Questions

I'm working on a login script. When the user successfully logs in I set
current code (not working): /^script\s*type=\text\/javascript/i.test(tagName)
I'm trying to get the current user login status via javascript sdk but I
I need to implement for current project some secure login in php. I wrote
So, when I run this login script, I get the following error: PHP Warning:
My current script allows me to send emails fine, but there are just some
I'm quite new to working with JSON. My current script outputs the following JSON:-
We current operate a datacenter that aggregates a bunch of login data and stores
I'm current designing a Rails application that uses a form for user login, then
I have the following rule in my current .htaccess file to redirect /videos/login/ requests

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.