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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:21:49+00:00 2026-05-27T19:21:49+00:00

if (strtolower($userDetail[username]) == strtolower($username) && $userDetail[password] == hash(sha256, $password . $userDetail[salt])) { if ($remember

  • 0
    if (strtolower($userDetail["username"]) == strtolower($username) && 
        $userDetail["password"] == hash("sha256", $password . $userDetail["salt"])) {       
        if ($remember == "true") { // Remember Me
            setcookie("logged", "$username", time()+60*60*24*365); // 1 Year
        } else {    
            setcookie("logged", "$username", time()+43200); // 12 Hours
        }
        header("Location: " . getenv("HTTP_REFERER"));
        die();
    } else {
        echo "Invalid login.";
    }

I’m trying to make the best possible login I possibly can. The major problem I’m seeing here is cookies. I’m no expert when it comes to this, so here are my main questions:

  1. What should I be setting my cookie as so someone can not easily duplicate the cookie?
  2. Should I be including the salt into the cookie?
  3. I’ve heard about tokens in addition to salts and having them change all the time. How is this supposed to work?

And I’m wondering if this call for my cookie above is even valid? What’s the right way to be doing this?

$loginCheck = $_COOKIE["logged"];
if (isset($loginCheck)) {
    // logged in
}
  • 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-27T19:21:50+00:00Added an answer on May 27, 2026 at 7:21 pm

    I like to leave the username intact, and have another cookie set as sha1(salt . user . pass)

    For instance:

    user=Truth
    uid=6cb8d1e35e5982a8ef738a8583a5d98d6fe2c484
    

    And then compare using the first cookie, against the database and the known hash.

    The way you’re doing it at the moment, anyone can copy a cookie and log in with anyone without even knowing their passwords. Just set

    logged=Admin expires Jan 1st 5000
    

    And you’re good to go. Once you have this second cookie to compare against, you’re much safer.


    As for the third question, yes, you can even shorten it to:

    if (isset($_COOKIE["logged"])) {
    

    But as I stated, you should move to the more secure format I’ve shown.


    See this Absolutely EPIC Tutorial on net.tutsplus.com for more on the subject.

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

Sidebar

Related Questions

I want to ignore case in a filter , My code: if (strtolower(isset($filterObject['name'])) &&
$fileSyntax = strtolower(preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($fileSyntax, ENT_QUOTES, 'UTF-8'))); // remove foreign character accents $fileSyntax =
function getYoutubeVideoId($url) { $urlParts = parse_url($url); if($urlParts === false) return false; if(isset($urlParts['host']) && strtolower($urlParts['host'])
I've asked about strtolower function. But when using foreign characters it doesn't convert them
Is it possible to use strtolower in the substitution part of preg_replace ? This
For the normal ajax request I use: strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' But this don't work
I have my class public function convert( $title ) { $nameout = strtolower( $title
I have names like this: $str = 'JAMES JIMMY SMITH' I run strtolower ,
I cannot use strtolower as it affects all characters. Should I use some sort
$_GET['search'] = ucfirst(strtolower(str_replace(_, ,urldecode($_GET['search'])))); For some reason it's adding slashes into the string similar

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.