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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:03:08+00:00 2026-05-15T22:03:08+00:00

This script works great. I call it in top of my scripts. But if

  • 0

This script works great. I call it in top of my scripts. But if a user that is NOT banned enters the site they get:

Notice: Trying to get property of non-object in index.php on line 20

The function:

// Check if conecting user is banned. If ban has expired delete row.
function check_bans()
{

// IP address
$user_ip = $_SERVER['REMOTE_ADDR'];

$query = mysql_query("SELECT ip, expire FROM bans WHERE ip = '$user_ip'");
$row = mysql_fetch_object($query);

$expire = $row->expire ? date('M d Y H:i', $row->expire) : 'Never';

// Did we find a match?
if (mysql_num_rows($query)) {

    // Has this ban expired? Then delete and let user inside.
    if ($row->expire != '' && $row->expire <= time())
        mysql_query("DELETE FROM bans WHERE ip = '$user_ip'") or die (mysql_error());
    else
        die("<h1 align=\"center\" style=\"color:maroon\">You have been IP banished. Ban will be lifted: $expire</h1>");

}

}
  • 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-15T22:03:09+00:00Added an answer on May 15, 2026 at 10:03 pm

    Because if the user has not been banned, the query yields zero results and the $row assignment gets assigned false (and not an object). So, that error happens because you’re attempting to call a method on a boolean. Try:

    function check_bans() {
    
        // IP address
        $user_ip = $_SERVER['REMOTE_ADDR'];
    
        $query = mysql_query("SELECT ip, expire FROM bans WHERE ip = '$user_ip'");
        $row = mysql_fetch_object($query);
        if($row) {
    
            $expire = $row->expire ? date('M d Y H:i', $row->expire) : 'Never';
    
            // Has this ban expired? Then delete and let user inside.
            if ($row->expire != '' && $row->expire <= time())
                mysql_query("DELETE FROM bans WHERE ip = '$user_ip'") or die (mysql_error());
            else
                die("<h1 align=\"center\" style=\"color:maroon\">You have been IP banished. Ban will be lifted: $expire</h1>");
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code is the core of a much larger script that works great in
I am using a script from this discussion: https://wordpress.stackexchange.com/a/14711/14649 It works great, but when
I have this script that works, but I need to change the format of
This example works great for one or the other, but not both: public void
I use this script to show an additional language menu additional, which works great
This script works fine on single click but on double click it shows both
I just finished this script it works well, but I am struggling to pass
We have a ubuntu test server that this simple script works fine on where
i have a TinyMCE implementation on my website that works great. But if the
I have a javascript that I downloaded off the net. This works great. My

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.