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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:07:48+00:00 2026-06-10T10:07:48+00:00

I currently have a PHP file which will search my MySQL database and see

  • 0

I currently have a PHP file which will search my MySQL database and see if a user is logged in. If they are logged in, it will echo “Welcome ‘username’. Logout” and if they’re not logged in it will echo “Login. Register.”

If I view this PHP file directly, it will echo out the correct text, depending on whether or not I am logged in. However, if I put into my HTML file using include it will only echo out the logged out text, regardless of whether I’m logged in.

Is there some conflict between PHP and HTML which will stop it from printing out the correct text maybe? It seems strange that it will work opening the PHP file itself, but not when it’s included in HTML.

HTML code:

<?php include "loginreg/check.php"; ?>

Would the fact it’s in a subfolder make a difference? Haven’t included the PHP code as that itself is working, but I have got it if you need to see it.

Cheers

PHP code:

// Gets IP address
$ip = visitorIP();

// Connect to database
mysql_connect(localhost, $username, $password);
@mysql_select_db($database) or die('Unable to select database');

$query  = "SELECT * FROM loggedin WHERE userip='$ip'";
$result = mysql_num_rows(mysql_query($query));
if ($result == '0') {
    mysql_close();
    loggedOut();
    return;
}

if (isset($_COOKIE['sid'])) {
    $sessionid = $_COOKIE['sid'];
}

$result = mysql_query($query);
while ($row    = mysql_fetch_assoc($result)) {
    if ($row['sessionid'] == $sessionid) {
        mysql_close();
        loggedIn($row['id']);
    } else {
        mysql_close();
        loggedOut();
    }
}

function visitorIP() {
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $TheIp = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $TheIp = $_SERVER['REMOTE_ADDR'];
    }
    return trim($TheIp);
}

function loggedIn($id) {
    global $username, $password, $database;
    mysql_connect(localhost, $username, $password);
    @mysql_select_db($database) or die('Unable to select database');

    $query  = "SELECT * FROM users WHERE id='$id'";
    $result = mysql_query($query);

    while ($row = mysql_fetch_assoc($result)) {
        $fname = $row['fname'];
        $sname = $row['sname'];
    }

    echo "<div class=\"fltrt\">Welcome, " . $fname . ". <a href=\"http://redsquirrelsoftware.co.uk/loginreg/logout.php\">Logout</a></div>";
}

function loggedOut() {
    echo "<div class=\"fltrt\"><a href=\"http://redsquirrelsoftware.co.uk/loginreg/login.html\">Login</a> <a href=\"http://redsquirrelsoftware.co.uk/loginreg/register.html\">Register</a></div>";
}
  • 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-10T10:07:50+00:00Added an answer on June 10, 2026 at 10:07 am

    Your issue is that you are setting cookies while inside a subdirectory. Use the path parameter of setcookie to ensure you’re setting the cookie in the root folder of your website:

    // Sets the cookie for the root of the domain:
    setcookie("username", "foo", time() + 60 * 60, "/");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a .htaccess file set up with this rule: RewriteRule ^([a-zA-Z0-9_-]+)$ user\.php?user=$1
I currently have code which will pull the first element from a database record
Currently I have this code: <?php echo '<meta name=robots content=noindex>'; $arr = json_decode(file_get_contents(http://media1.clubpenguin.com/play/en/web_service/game_configs/ paper_items.json),true);
I currently have a PHP form that uses AJAX to connect to MySQL and
I currently have a news website setup in PHP/MYSQL that's a bit old and
I have a PHP file which produces an Xml sitemap based on data which
Currently I have a legacy based non-MVC php framework which I need to update
My website file structure currently looks like this: marketplace.php cats.php On marketplace.php I have
i have an easy ajax script which sending data to php file with no
I have a 9000-line PHP file which consists of about 30 discrete areas, navigated

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.