Jump to content

mamanybono

Members
  • Posts

    5
  • Joined

  • Last visited

mamanybono's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I found the answer .mysql_query("CREATE TABLE {$country_name}_ip( id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, p1 VARCHAR(50), p2 VARCHAR(50), p3 VARCHAR(50), p4 VARCHAR(50), p5 VARCHAR(50))");
  2. Hi everybody,I just want to learn this, I have $country_name variable in my code and if $country_name=turkey, I need to create a table in database as turkey_ip because of this I wrote below code and it works good. But I wonder is there a way to not create $_ip variable. I mean I want to use $country_name variable and _ip string in mysql query so ı do not need one extra variable. $_ip=$country_name.'_ip'; mysql_query("CREATE TABLE $_ip ( id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, p1 VARCHAR(50), p2 VARCHAR(50), p3 VARCHAR(50), p4 VARCHAR(50), p5 VARCHAR(50))");
  3. Thank you boen_robot for your answer. I just tried to split this numbers because I want to record them into database in different colums so when I got a guest ip I able to compare it with my database. I am doing this because I need to learn guest's country but just country I don't care about city or state. One of my friend advice to me using preg_match_all function and this solved my problem. But until I understand the structure of preg_ functions and regex I studied around 4 hours. I can't concentrate on your code but I made a short research ip2long. I couldn't understant but you mean keep this ip adresses in IPv4 Internet network addres format(1320350348) instead of standard format (78.178.242.140). But if I don't understant this CIDR format 5.2.80.0/21 there is 21 ip adresses. And I got 1440 CIDR ip range for Turkey so approximately 1440*21=30240 numbers and think about I have Bulgaria's ip addresses too, İt's dublicate 2*30240=60480 numbers have to be checked. İnstead of that, I am going to sperate this 5.2.80.0/21 into 5 part like this 5 2 80 0 21 and sql query going to compare guest's first three part with my database if there is a matched, İt is going to check that, is the guest's fourth part number between my forth part number and fifth part number.
  4. 7,9,12 are the places of third "." and place of "/" and place of " " in this string 5.2.80.0/21 5.11.128.0/17. Actually I am trying to split this string at every third "." and every "/" and every " ". While ı am searchigt at web I found preg_splite function, right now I am working on it.
  5. Hi everybody, I am trying to write a code which record a CIDR (5.2.80.0/21 5.11.128.0/17) format ip list into mysql database. I have a problem at one part of my code. Code is the below. With this code I am trying to find every third "." character's place and every "/" character's place and every " " characters place. After finding the places the code record the places in to an array which name is $reference_points. The problem is that for exaple if I apply this code on this 5.2.80.0/21 5.11.128.0/17 string. The result should be $reference_points.[1]=7 $reference_points.[2]=9 $reference_points.[3]=12 but it shows $reference_points.[1]=7 $reference_points.[2]=9 $reference_points.[3]=23. And the full list of CIDR ip is attached. By the way I use a form on php page to take this list. The code part is which start fith FOR loop. Thak you very much. <div align="center"><form action="add_new_country.php" method="post"><table><tr><td>Country name:</td> <td><input type="text" maxlength="50" name="new_country_name" id="new_country_name" size="38" /></td></br></br></tr><tr><td>Country Ip Ranges:</td> <td><textarea rows="10" cols="30" name="country_ip_ranges" id="country_ip_ranges"> </textarea></td></br></br></tr><tr><td><input type="submit" name="submit" value="Add New Country" /></td><td></td></tr></table></form></div> <div align="center"><?phpif(isset($_POST["new_country_name"]) && isset($_POST["country_ip_ranges"]) && !empty($_POST["new_country_name"]) && !empty($_POST["country_ip_ranges"])){$country_name=@$_POST['new_country_name'];$country_ip_range=@$_POST['country_ip_ranges']; $sql=mysql_query("SELECT id FROM countries WHERE country_name='$country_name' LIMIT 1");$exist_count=mysql_num_rows($sql); if($exist_count==1){echo "The name of the country which you try to add is already exist in the system, please try to add different name.";}else{mysql_query("INSERT INTO countries (id,country_name) VALUES ('','$country_name')" );mkdir("$country_name");$dot=0;$reference_points=array();$reference_points_index=1; for($i=1;$i<=strlen(trim($country_ip_range));$i++){if(substr(trim($country_ip_range),$i-1,1)=='.' && $dot<3){$dot=$dot+1; if($dot==3){$reference_points[$reference_points_index]=$i;$dot=0;$reference_points_index=$reference_points_index+1;} }elseif(substr(trim($country_ip_range),$i-1,1)=='/'){$reference_points[$reference_points_index]=$i;$reference_points_index=$reference_points_index+1; }elseif(substr(trim($country_ip_range),$i-1,1)==' '){$reference_points[$reference_points_index]=$i;$reference_points_index=$reference_points_index+1;}}echo $reference_points[1].'<br/>';echo $reference_points[2].'<br/>';echo $reference_points[3].'<br/>';echo $reference_points[4].'<br/>';echo $reference_points[5].'<br/>';echo $reference_points[6].'<br/>';echo $reference_points[7].'<br/>';echo $reference_points[8].'<br/>';}}?></div> TR_cidr.txt
×
×
  • Create New...