PHP - Geoip Lookup Northern Ireland
Hi all,
I'm currently using Maxminds geoip and geoipcity databases to determine the users country but it struggles to determine if a visitor is from Northern Ireland (it just shows them as United Kingdom). Has anyone got (any) GeoIP to accurately determine Northern Ireland visitors? Thanks Similar TutorialsHey there i just find out by mistake that PHP Can Return the ISPs CC etc O.o by looking here but it gives me parse errors on any script im trying to run.. for example this is giving me <?php $isp = geoip_isp_by_name('www.example.com'); if ($isp) { echo 'This host IP is from ISP: ' . $isp; } ?> Fatal error: Call to undefined function geoip_isp_by_name() in C:\wamp\www\IP\index1.php on line 2 Do i need to activate some PHP Settings to make it work? hey guys ive decided to use geoip via my database on my server.
now i've download blocks.cvs and location.cvs from:
http://geolite.maxmi...City-latest.zip
but when trying to load block.cvs in excel it says:
Failer to load completly
does anyone know of another source where i can that/these files from please?
thank you
Hi I'm using an IP database to correctly (+/-) serve related ads based on country. This seems to work fine BUT when tested on a USA proxy (I'm in the UK) I am getting TWO ads served, one for USA (correctly) and one for the UK (proxy error?). When surfing via proxy from the Netherlands I get no image at all. Looking for somebody to see what I've done wrong he $server = 'localhost'; // MySQL hostname $username = '***'; // MySQL username $password = '***'; // MySQL password $dbname = '***'; // MySQL db name $db = mysql_connect($server, $username, $password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql = 'SELECT country FROM ip2nation WHERE ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") ORDER BY ip DESC LIMIT 0,1'; list($country) = mysql_fetch_row(mysql_query($sql)); switch ($country) { case 'us': // Image or USA echo '<img src="impact/samsungN210PLUS_usa.jpg">'; case 'uk': // Image for UK echo '<img src="impact/samsungN210PLUS_uk.jpg">'; default: // Image for everybody else (europe) echo '<img src="impact/samsungN210PLUS_europe.jpg">'; end; } echo '<div width="420" class="loc"><span class="loc" align="center">Not from '; $sql = 'SELECT c.country FROM ip2nationCountries c, ip2nation i WHERE i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1'; list($countryName) = mysql_fetch_row(mysql_query($sql)); // Output full country name echo $countryName; $domain = str_replace("www.","", $_SERVER['HTTP_HOST']); echo '? Choose your flag: <a href="http://uk.' .$domain. '"><img src="images/flags/ukflag.gif"></a> <a href="http://usa.' .$domain. '"><img src="images/flags/usaflag.gif"></a> <a href="http://europe.' .$domain. '"><img src="images/flags/euflag.gif"></a></span></div>'; All help appreciated and thanks in advance. PS. The script is working he http://darrenbassett.com/trial if somebody in the USA wishes to check and let me kow if it is a proxy surfing error (seeing BOTH IP's). Not a real website just a 'play' page to get the bones of the script working. Firstly hello - I've not posted on here before! I'm after a bit of advice if possible - I recently upgraded to a new server with RHEL6 and PHP 5.3.10 from a previous server with RHEL4 and PHP 5.2.17. I have some postcode lookup software running that functioned perfectly on our old server, but seems to cause a server 500 error with the updated version of PHP. I cannot downgrade to PHP 5.2.17 so I need to fix the issue or workaround it. A snippet of the code is as follows: Code: [Select] $data = simplexml_load_string(file_get_contents($url)); foreach ($data->Rows->children() as $row) { I have narrowed down the cause of the failure to "children()" - it seems that anything with the curly brackets causes the code to die? As you may guess I'm not a guru with PHP - I just know enough to get by. What do I need to do to get this working? Many thanks in advance. Danny I am running a search for a specific link on my site in order to make a big change but some of my entries are a little malformed. How do I make this script go to the next record if no match is found. Here are the two pieces of code: $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ echo $row['name']; echo "<br />"; //After the page is loaded search for specified links for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $purl = substr($url, 30,300); //Here I would like to continue the while loop //Maybe if i could find the value "No entities were found" it would escape it just as well? At the end of the code I would like to continue the while loop if i could find the value "No entities were found" on the page that is missing the link I need. Thanks for the help. Is there a way, and if so how would I detect the state of the user on my site. Like by using their ip? Thanks! I am getting a little frustrated, and I need some help. I've working on this all day (I am new... otherwise I'd fly through it). This is a simple problem I just can't seem to put a ' in the right spot or something... Here's the gist. In file myphotos.php is the following: <?PHP include('functions.php'); $link $title = 'Light Graspers Certification'; $linktent = '<div class="titler">Photo Review</div><div class="contentm">'.$data[index].'</div>'; $excess = '<div class="titlerex">Testimonials</div><div class="contentmex">'.$displayoptions.'</div>'; echo getphoto($title, $linktent, $excess); ?> Now my goal is under $displayoptions the following will happen. SELECT DISTINCT name FROM homework WHERE uid='$loggedin' ORDER BY id"; With proper code I should see a distinct list of all the "name" rows. The user clicks on it to be directed to just those rows... etc... Here is was some old code I tried manipulating to get the same result... but I couldn't seem to get it to work. Of course I only need one column in my new code. Any help would be a appreciated. Adam $columns = 5; //change the query to get another field from the database $query = "SELECT DISTINCT city,state FROM church WHERE state='$state' ORDER BY city"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); $rows = ceil($num_rows / $columns); while($row = mysql_fetch_array($result)) { $data[] = $row['city']; //store the other field into an array } for($i = 0; $i < $rows; $i++) { { echo "<tr valign=bottom>"; echo "<td bgcolor=#2172A1 colspan=10><img src=img/blank.gif width=1 height=1></td>"; echo "</tr>"; } echo "<TR valign=center>"; for($j = 0; $j < $columns; $j++) { if(isset($data[$i + ($j * $rows)])) { echo "<td class=tabval><b><a href='findnew.php?state=".$state."&city=" . $data[$i + ($j * $rows)] . "'>" . $data[$i + ($j * $rows)] . "</a></b></td>"; } } echo "</TR>"; } echo "<tr valign=bottom>"; echo "<td bgcolor=#2172A1 colspan=10><img src=img/blank.gif width=1 height=8></td>"; echo "</tr>"; echo "$state represents $num_rows3 \n of our $num_rows2 churches\n that we serve. "; } I have been learning php and have put together a simple site to track vehicle faults and repairs, but now i am trying to transfer it to cakephp framework to make it easier to work with. My problem is that i have 4 tables,
the fault and repair
a list of vehicles
a list of symptoms
a list of fault codes.
Each repair can have 3 vehicles, 3 symptoms and 3 codes relating to it so i have lookup table to link the fault/repair id to the symptoms, code and vehicles.
i have setup basic code for the vehicle , symptom and fault code models like this:
public $hasAndBelongsToMany = array( 'Fault' => array( 'className' => 'Fault', 'joinTable' => 'Faults_vehicles', 'foreignKey' => 'vehicle_id', 'associationForeignKey' => 'fault_id' ) ); and this lets me search for any faults in the faults table with a given vehicle ID, and this works fine. My problem is how can i set it up so i can do a search for faults in the Faults table with a given vehicle ID and a given symptom ID that have a matching Fault code ID. I am very new to php and have only just started using cakephp so sorry in advance if this makes no sense at all. thanks for your time j Throughout the application I'm building, I include a db.php file which has the information about the local database so that I can use it wherever I do a database call. However, I am now using a second database located on a remote server in order to fetch additional information not stored on the local database, inside a while loop. This fail miserably and I have tested many things and need a bit of guidance. Code simplified: Code: [Select] function grab_expiration_date ($number) { $remote_link = mysql_connect('remote_host', 'user', 'pass'); $remote_connect = mysql_select_db('remote_db', $remote_link); $query = "SELECT ExpirationDate FROM remote_table WHERE Number='$number'"; $result = mysql_query($query, $remote_link); $num_rows = mysql_num_rows($result); if ($num_rows == 1) { $r = mysql_fetch_assoc($result); $expire_date = $r['ExpirationDate']; mysql_close($remote_link); return $expire_date; } else { return false; } } $query = "SELECT Number FROM local_table; $result = mysql_query($query, $local_link); while ($r = mysql_fetch_assoc($result)) { $number = $r['Number']; $expire_date = fetch_expiration_date($number); if ($expire_date) { $query2 = UPDATE local_table SET ExpirationDate='$expire_date' WHERE Number='$number'"; $result2 = mysql_query($query2, $link); if (!$result2) { echo 'Could not update the Expiration Number because: ' . mysql_error(); exit(); } } else { echo 'Nothing found, or dublicates'; } } The attempt of update the local table fails, and mysql_error() does not even return anything, stating what's wrong. In the past, I fetched this information from a website using CURL, but since I now have access to the database, hitting the database is by far faster. Any help would be much appreciated. I have found postings close, but not close enough to find my error. I am looking up data from a MySql table and putting it in a dropdown box on a form. I can select the item, but apparently not really. I am not able to echo it, or post it to a record. I'm sure I am missing something simple, but... Code attached if anyone can show me the errors of my ways. Thank you. Hello all,
For the UPDATE portion of my CRUD WebApp what I would like to do is to bring in (and display) the values (of a selected row) from my transaction table.
This is working just fine for all fields which are of the "input type". The problem I'm having is with two fields which are of the "select type" i.e. dropdown listboxes.
For those two fields, I would like to bring in all the valid choices from the respective lookup/master tables, but then have the default/selected value be shown based on what's in the transaction table. The way I have it right now, those two fields are showing (and updating the record with) the very first entry's in the two lookup tables/select query.
The attached picture might make things a little bit clearer. You'll notice in the top screenshot that the first row (which is the one I'm selecting to update) has a "Store Name" = "Super Store" and an "Item Description" = "Old Mill Bagels". Now, when I click the "update" botton and I'm taken to the update screen, the values for those two fields default to the very first entries in the SELECT resultset i.e. "Food Basics" and "BD Cheese Strings". Cricled in green (to the top-left of that screenshot) is the result of an echo that I performed, based on the values that are in the transaction record.
I cannot (for the life of me) figure out how to get those values to be used as default/selected values for the two dropdown's...so that if a user does not touch those two dropdown fields, the values in the transaction table will not be changed.
Your help will be greatly appreciated.
Here's a portion of the FORM code:
<form class="form-horizontal" action="update.php?idnumber=<?php echo $idnumber?>" method="post"> <?php // Connect to Store_Name (sn) table to get values for dropdown $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT DISTINCT store_name FROM store_master ORDER BY store_name ASC"; $q_sn = $pdo->prepare($sql); $q_sn->execute(); $count_sn = $q_sn->rowCount(); $result_sn = $q_sn->fetchAll(); Database::disconnect(); // Connect to Item_Description (id) table to get values for dropdown $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT DISTINCT product_name FROM product_master ORDER BY product_name ASC"; $q_id = $pdo->prepare($sql); $q_id->execute(); $count_id = $q_id->rowCount(); $result_id = $q_id->fetchAll(); Database::disconnect(); foreach($fields AS $field => $attr){ $current_store_name = $values['store_name']; $current_item_description = $values['item_description']; //Print the form element for the field. if ($field == 'store_name') { echo $current_store_name; echo '<br />'; echo $current_item_description; echo '<div class="control-group">'; echo "<label class='control-label'>{$attr['label']}: </label>"; echo '<div class="controls">'; //Echo the actual input. If the form is being displayed with errors, we'll have a value to fill in from the user's previous submission. echo '<select class="store-name" name="store_name">'; // echo '<option value="">Please select...</option>'; foreach($result_sn as $row) { echo "<option value='" . $row['store_name'] . "'>{$row['store_name']}</option>"; } // $row['store_name'] = $current_store_name; echo "</select>"; echo '</div>'; echo '</div>'; } elseif ($field == 'item_description') { echo '<div class="control-group">'; echo "<label class='control-label'>{$attr['label']}: </label>"; echo '<div class="controls">'; echo '<select class="item-desc" name="item_description">'; // echo '<option value="">Please select...</option>'; foreach($result_id as $row) { echo "<option alue='" . $row['product_name'] . "'>{$row['product_name']}</option>"; } echo "</select>"; echo '</div>'; echo '</div>'; } else { echo '<div class="control-group">'; echo "<label class='control-label'>{$attr['label']}: </label>"; echo '<div class="controls">'; //Echo the actual input. If the form is being displayed with errors, we'll have a value to fill in from the user's previous submission. echo '<input type="text" name="'.$field.'"' . (isset($values[$field]) ? ' value="'.$values[$field].'"' : '') . ' /></label>'; echo '</div>'; echo '</div>'; }And here's some other declarations/code which I think might be required. $fields = array( 'store_name' => array('label' => 'Store Name', 'error' => 'Please enter a store name'), 'item_description' => array('label' => 'Item Description', 'error' => 'Please enter an item description'), 'qty_pkg' => array('label' => 'Qty / Pkg', 'error' => 'Please indicate whether it\'s Qty or Pkg'), 'pkg_of' => array('label' => 'Pkg. Of', 'error' => 'Please enter the quantity'), 'price' => array('label' => 'Price', 'error' => 'Please enter the price'), 'flyer_page' => array('label' => 'Flyer Page #', 'error' => 'Please enter the flyer page #'), 'limited_time_sale' => array('label' => 'Limited Time Sale', 'error' => 'Please enter the days for limited-time-sale'), 'nos_to_purchase' => array('label' => 'No(s) to Purchase', 'error' => 'Please enter the No. of items to purchase') ); ... ... .... { // If [submit] isn't clicked - and therfore POST array is empty - perform a SELECT query to bring in // existing values from the table and display, to allow for changes to be made $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM shoplist where idnumber = ?"; $q = $pdo->prepare($sql); $q->execute(array($idnumber)); $values = $q->fetch(PDO::FETCH_ASSOC); if(!$values) { $error = 'Invalid ID provided'; } Database::disconnect(); }If there's anything I've missed please ask and I'll provide. Thanks Hi, I've currently started to modify a chat script of mine to output a moderation panel but the moderation page seems empty(blank) every time I load it. What im trying to do is to take the ID part in my URL via the $_GET and look it up in my database table in the column named id, then select that specific row to be able to retrieve the StringyChat_ip and place it into another table to ban the IP and the second thing im trying to do is to be able to delete the specific row from my table.
My Http link look something like
http://imagecrab.fre.../ban.php?id=159
and my ban.php page where I want to lookup the 159 part and do the banning etc looks like
<? include("admin_code_header.php"); if ($_POST["DeletePost"]) { $id = $_POST['id']; $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; mysql_query($query); echo "ID removed from system: ".$id; } if ($_POST["BanIP"]) { $IP_To_Add = $_POST["ip"]; $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")"; $result = mysql_query($sql); } $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'",$db); while ($myrow = mysql_fetch_array($result)) { $msg = $myrow["StringyChat_message"]; $idm = $myrow["id"]; ?> <html> <form name="form<? echo $myrow["id"];?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="DeletePost" type="submit" id="DeletePost" value="Delete"> <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>"> </form> </html> <? } ?> My login script stores the user's login name as $_SESSION[ 'name'] on login. For some unapparent reason, i'm getting errors stating that $user and $priv are undefined variables, though I've attempted to define $user as being equal to $_SESSION['name'], using $user to look up the the user's privilege level (stored as the su column ) in the SQL table, and then where the result of the sql query is $priv which is then evaluated in an if statement. I can't seem to figure out why this might not be working. The code I'm using: <?php session_start(); function verify() { //verify that the user is logged in via the login page. Session_start has already been called. if (!isset($_SESSION['loggedin'])) { header('Location: /index.html'); exit; } //if user is logged in, we then lookup necessary privleges. $_SESSION['name'] was written with the login name upon login. Privleges // are written in db as a single-digit integer of of 0 for users, 1 for administrators, and 2 for special users. $user === $_SESSION['name']; //Connect to Databse $link = mysqli_connect("127.0.0.1", "database user", "password", "database"); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } //SQL Statement to lookup privlege information. if ($result = mysqli_query($link, "SELECT su FROM accounts WHERE username = $user", MYSQLI_STORE_RESULT)) { //LOOP TO CYCLE THROUGH SQL RESULTS AND STORE Privlege information as vairable $priv. while ($row = $result->fetch_assoc()) { $priv === $row["su"]; } } // close SQL connection. mysqli_close($link); // Verify privleges and take action. Only a privlege of "1" is allowed to view this page. A privlege of "2" indicates special //accounts used in other scripts that have certain indermediate additional functions, but are not trusted administrators. if ($priv !== 1) { echo $_SESSION['name']; echo "you have privlege level of $priv"; echo "<br>"; echo 'Your account does not have the privleges necessary to view this page'; exit; } } verify(); ?>
|