Current location: Hot Scripts Forums » Programming Languages » PHP » IP logging and blocking help...


IP logging and blocking help...

Reply
  #1 (permalink)  
Old 07-07-05, 06:52 PM
acctman acctman is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
IP logging and blocking help...

can someone help with a simiple PHP code that does the following...

When user visits show.php check mysql db table for there IP, if IP is present then deny access to that page (redirect to main.php) If IP is not present then store IP in the database.

i know a little bit about php so any example would be great
Reply With Quote
  #2 (permalink)  
Old 07-07-05, 07:38 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
In a nutshell:
PHP Code:

<?php


$ip_found 
mysql_num_rows(mysql_query("SELECT ip FROM table_name WHERE ip = '" $_SERVER['REMOTE_ADDR'] . "'"));

if (
$ip_found 0)
header("location: main.php");
else
mysql_query("INSERT INTO table_name (ip) VALUES (" $_SERVER['REMOTE_ADDR'] . ")");

// rest of page here

?>
Reply With Quote
  #3 (permalink)  
Old 07-08-05, 12:09 AM
acctman acctman is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
can I use two database? the following is what i use to grab the user name and gender for the login. for the ip logging i what to store and get info from a different database "chatdb" is there a trick to working with two db's ?


PHP Code:



<?

        
include $_SERVER['DOCUMENT_ROOT'] . '/dbmain.php';
        include 
$_SERVER['DOCUMENT_ROOT'] . '/kernel/db_funcs/mysql.php';
        
sql_connect($db_server$db_user$db_pass);
        
sql_select_db($db_name);



session_start();
$user=$_SESSION['user'];

if(
$user=="") {
header("Location: index.php");
}

$res sql_query("select * from rate_members where m_user='$user'");
$info mysql_fetch_assoc($res);
$u_type $info['m_type'];
if (
$u_type == 1) {
$sex "F";
} else {
$sex "M";
}
?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 06:54 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.