Jump to content

Urgent! Hwo to accesss data from MYSql database in PHP?


natasha_thomas

Recommended Posts

Folks,

 

I need an urgent help. Hope here ppl will help out.

 

Requirement:

What i want is, when a visitor comes to my site, his IP will be captures in $ip (refer Coding below), as you can see in coding, i want this IP to be searched in MYSQL database (I have a list of 25000 IPs there), and if the $ip matches with the MYSQL database IP, it should make $is_bot as TRUE.

 

In the existing codign this thing has been taken care but there is not Database Lookup feature, but Text file look up, and if i have moer than 25000 IPs in the Text fie then i believe the lookup will take hell lot of time, so i think looking up in MY Sql database will be way faster.

 

Request:

I rquuest guys here, to help me out with the exact codes that i should add int he existing codign so that i can achieve my requirement.

 

We have a Beer deal, should you happen to visit DC.  ;D

 

Warm Regards,

Natasha Thomas

 

 

Reference: Coding

 

<?

// PHPLOCKITOPT NOENCODE

 

// NOTES:

// $ip_array contains the list of IPs you have in your ip_list.txt file

// $ip is the IP address of the current visitor.

// $agent is the user agent string of the current visitor.

// $referrer is the referrer sent by the visitor's browser, if any.

// $cloaked_url is the cloaked URL for the campaign being visited.

 

// You can add additional criteria for detecting "bots" below, but you better know what you are doing!  To add IPs to detect, simply put them in the ip_list.txt file.

 

if(

@in_array($ip,$ip_array)

|| stristr(strtolower($agent),"bot")

|| stristr(strtolower($agent),"spider")

|| stristr(strtolower($agent),"slurp")

)

{

$is_bot = true;

}

 

// You can add additional criteria for detecting "networks" below, but you better know what you are doing!

 

if(

(

@in_array($ip,$ip_array)

|| $keyword == ""

|| $keyword == "-"

|| $keyword == "test"

|| @stristr(strtolower($keyword),"searchtext")

|| @stristr($keyword,"{")

|| @stristr($keyword,"[")

|| @stristr(strtolower($referrer),"trafficvance")

|| @stristr(strtolower($referrer),"addonnetwork")

)

 

&& @!stristr(strtolower($referrer),strtolower($cloaked_url)) // DO NOT CHANGE OR REMOVE THIS LINE

&& @$_GET['mode'] != "test") // DO NOT CHANGE OR REMOVE THIS LINE

{

$enable_cloak=true;

}

 

if($is_bot == true || $enable_cloak == true)

{

$fwrite=@fopen("data/bots.txt","a+"); // Will write this bot's data to a text file called bots.txt

@fwrite($fwrite,$accesstime."\t".$ip."\t".$link."\t".$agent."\t".$referrer."\n");

@fclose($fwrite);

die(header("Location: http://".$cloaked_url)); // This is what should happen if it is determined that the cloaked URL should be shown to the current visitor.  Be SURE you know what you're doing if you change this.

}

 

?>

 

Link to comment
Share on other sites

Try not to post two topics.

 

If you don't have a database or a table for it yet, you'll need a setup file.

 

<?php
$db_name = "my_database"; //if you create one manually in your cpanel, change the name
$db_pass = ""; //you have to get this from your host
$db_user = ""; //you have to get this from your host
$mysql_host = "localhost"; //could be different, check details on your cpanel

$connect = mysql_connect($mysql_host,$db_user,$db_pass) or die("<h1>Could not connect to MySQL:</h1>".mysql_error());

//attempt to select database
$select = mysql_select_db($db_name);

//if failure to select, attempt to create it
if(!$select){
   $create = mysql_query("CREATE DATABASE $dn_name") or die("<h1>Could not select OR create database $dn_name</h1>".mysql_error());
   $select = mysql_select_db($db_name) or die("<h1>Could not select database $db_name</h1>".mysql_error());
}

//if all went well create table to hold ip address
mysql_query("
   CREATE TABLE IF NOT EXISTS ip_addresses(
      id INT(11) NOT NULL AUTO_INCREMENT,
      ip VARCHAR(20) NOT NULL UNIQUE,
      PRIMARY KEY(id))") or die("<h1>Could not create table ip_addresses</h1>".mysql_error());

echo '<h1>Setup was a success</h1>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.