Results 1 to 5 of 5

Thread: [PHP] Banning users - help format code for html

  1. #1
    Digitalosophy
    n/a
    posts
    Guest

    [PHP] Banning users - help format code for html

    I made a small system to where I can ban users from my webserver and print a reason for them getting banned.

    My problem is now this:
    The way my code is set up, php checks to see if the current IP address matches an IP address from the ban list. If true, print the reason and such. If false display the website.

    Now of course, I want to add this to all my pages currently on my webserver including my blog.

    To reformat the HTML to work with this system would definatly be a pain in the ***.

    So my question is there any other way I can do this, so I don't have to reformat the HTML? Maybe I'm just not thinking properly at the moment.

    PHP Code:
    <?php
    //already connected to db of course
    $s $_SERVER["REMOTE_ADDR"];
    $ipbancheck "SELECT * from banip where IP='$s'";
    $result mysql_query($ipbancheck);
    $row mysql_fetch_array($result);
    if(
    $s $row["IP"]){
        echo 
    "<p>Your IP Address has been banned from this webserver ";
        echo 
    htmlspecialcharsstripslashes($row["IP"])).'<br>';
        echo 
    "Reason: ";
        echo 
    htmlspecialcharsstripslashes($row["REASON"]));
        echo 
    "</p>";
    }else{
        echo 
    "Display Website";
        
    // here's the problem
        // i don't want to have to reformat all my html
        // for php, i have many pages i want to do this for.
        
        
    }
    ?>

  2. #2
    just save it to a file and include it in each of your pages
    <?PHP include "banlist.php"; ?>

    Don't have the else, just put die(); at the end of the if statement.

    PHP Code:
    <?php 
    //already connected to db of course 
    $s $_SERVER["REMOTE_ADDR"]; 
    $ipbancheck "SELECT * from banip where IP='$s'"
    $result mysql_query($ipbancheck); 
    $row mysql_fetch_array($result); 
    if(
    $s $row["IP"]){ 
        
    $error "<p>Your IP Address has been banned from this webserver "
        
    $error .= htmlspecialcharsstripslashes($row["IP"])) . "<br />\n"
        
    $error .= "<b>Reason:</b><br />\n"
        
    $error .= htmlspecialcharsstripslashes($row["REASON"])); 
        
    $error .= "</p>"
    die(
    $error);
    }
    ?>

  3. #3
    Digitalosophy
    n/a
    posts
    Guest
    ha good looks man, I'll give that a go in a little while

  4. #4
    Digitalosophy
    n/a
    posts
    Guest
    Works perfectly, thanks.

  5. #5
    Any time man.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012