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

The Archive Base Latest Questions

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

I am trying to get php to choose which link should appear depending on

  • 0

I am trying to get php to choose which link should appear depending on if this person is logged into my site using cookies.I tried to code this my self but it isn’t working.So How would I go about doing this the right way here is my code:

<?php
if(isset($_COOKIE['maxgee_me_user'])) {
$username = $_COOKIE['maxgee_me_user']; 
$password = $_COOKIE['maxgee_me_password']; 
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))   

    { 



//if the cookie has the wrong password, echo's login 

    if ($password != $_COOKIE['maxgee_me_password']) 

        {           ?> <a href="logout.php"><?php echo "Logout"; ?></a> &nbsp;&nbsp 
         <?php
    else {
    ?> <a href="loginpage.php"><?php echo "User Login";} ?></a> &nbsp;&nbsp;
  • 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-13T05:14:10+00:00Added an answer on June 13, 2026 at 5:14 am

    Quite a lot of errors on your code.
    First of all, you need to use both user name and password when checking if a valid user exist. Assuming you have the pwd saved as well in you table.

        $check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password='$password'") or die(mysql_error());
    

    And use mysql_num_rows($check)>0 to see if a valid user found.
    Following is a complete code, but do note this is bad coding practise which you say you are working on it.

    <?php
    if(isset($_COOKIE['maxgee_me_user']))
    {
        $username = $_COOKIE['maxgee_me_user']; 
        $password = $_COOKIE['maxgee_me_password']; 
        $check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password='$password'") or die(mysql_error());
        if (mysql_num_rows($check)>0) 
        {
    
            ?>
            <a href="logout.php">Logout</a> &nbsp;&nbsp 
            <?php
        }
        else
        {
            ?>
            <a href="loginpage.php"><?php echo "User Login"; ?></a> &nbsp;&nbsp;
            <?php
        }
    }
    else
    {
        ?>
        <a href="loginpage.php"><?php echo "User Login"; ?></a> &nbsp;&nbsp;
        <?php
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using php I am trying to get some data from a .csv file which
I was trying to get PJAX working with my PHP site, this is the
I have this php script in an external file trying to get random question
I am trying to get php's namespace technique down but having some issues here:
I'm trying to get php to automatically pass the session ID via url, even
I'm having a really difficult time trying to get php to connect to SQL
I'm trying to get the php executable to parse scripts, but it's not working.
I am trying to get the PHP PDO driver for SQL server working. I
I'm trying to get PhantomJS to run via PHP. When I run the JavaScript
I am trying to get data back from a PHP file assigned with GET

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.