Results 1 to 9 of 9

Thread: [RESOLVED] help plase

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] help plase

    Can anyone help me please.

    im trying to show my site to people that are not banned from my website the html part at the top should only show when they are not banned and if they are banned then it show display the php you are banned code. When they are banned it still shows the html coade part aswell.

    PHP Code:
    <B>Website Coming Soon</b>

    <?php
        
    include("config.php");
        
    mysql_connect("$host""$username""$password");
        
    mysql_select_db($db) or die(mysql_error());
        
    $sql "SELECT * FROM ip";
        
    $result mysql_query($sql);
        
    $row mysql_fetch_array($result) or die(mysql_error());
        if (
    $_SERVER["REMOTE_ADDR"] == $row["ip"] )
        {
            echo 
    "You are banned from viewing this website";
        }
    ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: help plase

    PHP Code:
    <?php
        
    include("config.php");
        
    mysql_connect("$host""$username""$password");
        
    mysql_select_db($db) or die(mysql_error());
        
    $sql "SELECT * FROM ip";
        
    $result mysql_query($sql);
        
    $row mysql_fetch_array($result) or die(mysql_error());
        if (
    $_SERVER["REMOTE_ADDR"] == $row["ip"] )
        {
            echo 
    "You are banned from viewing this website";
        }
        else
        {
        
    ?>
        <b>Website Coming Soon</b>
        <?php
        
    }
    ?>
    If you put the HTML at the top, it will show no matter what the PHP code is after that. What you want is either print the banned message or else (from the if banned statement) print the other message


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: help plase

    I need to show my website to the people that are not banned and show the You are banned from viewing this website message to people that are on my banned list?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: help plase

    Doesn't that work? If instead of the <b>Website Coming Soon</b> part you put the code of your website?

    PHP Code:
    <?php
        
    include("config.php");
        
    mysql_connect("$host""$username""$password");
        
    mysql_select_db($db) or die(mysql_error());
        
    $sql "SELECT * FROM ip where `ip` = '".$_SERVER["REMOTE_ADDR"]."'"//select only the entries where the ip field matches the ip of the current user
        
    $result mysql_query($sql) or die(mysql_error()); //execute the query
        
    if (mysql_num_rows($result) > 0//if at least one row was returned from the query, in other words the IP was in the list, print the message and stop loading the page
        
    {
            die(
    "You are banned from viewing this website");
        }
    ?>

    load website normally here.
    If the IP is found in the table the the die function will run, printing the message and not loading the rest of the page.

    Of course, I just noticed that you either have to loop through the IPs you select or add a where clause to your SQL statement to check for the IP.

    Edit: I changed your SQL statement. I haven't tested it, I just typed it here, but I think it should work...
    Last edited by manavo11; Oct 13th, 2008 at 11:01 AM.


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: help plase

    I have tryed

    PHP Code:
    <?php
        
    include("config.php");
        
    mysql_connect("$host""$username""$password");
        
    mysql_select_db($db) or die(mysql_error());
        
    $sql "SELECT * FROM ip";
        
    $result mysql_query($sql);
        
    $row mysql_fetch_array($result) or die(mysql_error());
        if (
    $_SERVER["REMOTE_ADDR"] == $row["ip"] )
        {
            die(
    "You are banned from viewing this website");
        }
    ?>

    load website normally here.
    if the ip isnt banned then it shows a blank page.
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: help plase

    Have a look at my edits above


    Has someone helped you? Then you can Rate their helpful post.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: help plase

    yeah works now but will this work when i add more ip address's?

    Also how do i make a page for me to add ip's to the database.? I have been struggling on it?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: help plase

    u able to help me?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  9. #9
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: help plase

    please DO NOT bump threads.

    also, using die() is not good practice. I forget why, but i think it has to do with running process, and your stopping them in the middle. so dont do it.
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width