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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:58:28+00:00 2026-05-18T09:58:28+00:00

Hello I have a question. I have set up my login system with cookies

  • 0

Hello I have a question. I have set up my login system with cookies and it works. But I wonder is there a more clean version of doing this.

<?
include('../config/db_config.php');

$username = $_COOKIE['user'];
$password = $_COOKIE['pass'];

$result = mysql_query("SELECT * FROM users WHERE isadmin = 1");

while($row = mysql_fetch_array($result))
{
    if($username == $row['username'] && $password == $row['password'])
    {
        //User entered correct username and password
        echo("ALLOW");
    }
    else
    {
        //User entered incorrect username and password
        echo("DENY");
    }
}
?>

You see I want all my content to be shown ONLY if I am logged in as admin. So what, now only way of doing this would be ECHO’ing out my HTML/PHP/Javascript instead of echoing ALLOW because if I just include(“somepage.php”) there that page would still be avialable for usage without logging in, and even if I do same check there I still would be ECHO’ing out everything.

  • 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-18T09:58:29+00:00Added an answer on May 18, 2026 at 9:58 am
    • Why are you loading every user, then comparing the username and the password? Wouldn’t be easier to load a single user matching the username and the password?

    • Loading a single user will allow to remove the while().

    • In PHP, don’t use mysql_query; do use PDO (if need, google for it to know why it’s better).

    • Check your input (quite optional here, I agree).

    • Do never store passwords in plain text format.

    You can probably do something like (I haven’t used PHP/PDO for years, so the code may be inexact):

    if (strlen($username)> 128)
    {
        // Something wrong. The username is too long.
    }
    
    $hash = sha1($password);
    $sth = $dbh->prepare('if exists(select * from users where isadmin = 1 and username = :username and password = :password) select 1 else select 0');
    $sth->bindParam(':username', $username, PDO::PARAM_STR, 128);
    $sth->bindParam(':password', $hash, PDO::PARAM_STR, 40);
    $sth->execute();
    $isFound = $sth->fetchAll();
    if ($isFound)
    {
        // User entered correct username and password.
        echo 'ALLOW';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about the following statement in tcl set hello [format %x
Hello guys and sorry for such a long question, but... I have a C#
hello i have this question i was trying to find a way to call
Hello i have a question on picking random entries from a database. I have
Hello is have a question for a school assignment i need to : Read
hello I have a small question in objective-C memory management. I know that if
Hello this is may first question and I have found so far the following
Hello guys sorry if the question looks stupid to you. i have 3 tables
I have the following regexp: (?P<question>.+(?<!\[\[)) It is designed to match hello world! in
i have this: <div id=parent style=overflow:auto> ... <div id=test>Hello</div> ... </div> My question is:

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.