PHP - Current City From Ip Address
ok guys, i know you guys are awesome and I always get the help and I need some help in
figuring the current city and the metropolitan area from an ip address. For example, if I am in Harlem, NY, I need to get the Harlem and New York. I have a code that is partially working but not accurate enough, please guys help, something like groupon will do. Code: [Select] function currentCity () { ( ( (float)phpversion() < 5.3 ) ) ? die ( 'There is something wrong!' ) : ''; $site = file_get_contents( "http://www.google.com/search?q=VBXMCBVFKJSHDKHDKF" ); $getLocationViaGoogle = function ( $html ){ $regex = "#<\w+\s\w+=\"tbos\">([^<]{3,})<\/\w+>#i"; preg_match_all( $regex, $html, $matches ); return $matches[1][0]; }; print $getLocationViaGoogle( $site ); } Similar TutorialsHello - I've come to an issue with something I'm working on and have searched around with no luck. When editing user accounts I want it to not be able to change the e-mail address into existing ones on other rows, but when submitting the form it takes into account that this particular rows email address is the same as the one which was sent via $_POST and throws up the error. The desired behaviour I want is for it to ignore the ID of the row which was posted, but take into account every other row. Here's the code as it stands at the moment: $email = $_POST['email']; $checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); } if (mysql_num_rows($checkemail) > 0) { return $this->error("The e-mail address you provided is already associated with an account."); } In my registration form there are many form elements to give users' details for registration in my web site. among those elements there are two select boxes for user to select their district and city. I have created these two select box using ajax. Therefor a user select a district then automatically ajax creating second select box for cities is populating. I used separate php page called findcity.php to create city select box. I called this findcity.php page from my original register.php page through onChange attribute. and there I passed the district id with the url to findcity.php page. like wise, Now I need to bring city id to my original register.php page when user select a city from city select box in findcity.php page. my problem is that. I tried to get city Id to register.php page but still I couldn't get it. city id is needed me to send to the database with other form elements' values. can anybody help me to fix my problem? here is my coding for your reference. This code is, from my register.php page Code: [Select] <div> <label for="district">District <img src="../images/required_star.png" alt="required" /> : </label> <?php require_once ('../includes/config.inc.php'); require_once( MYSQL2 ); $query="select * from district order by district_id"; $result = mysqli_query( $dbc, $query); echo '<select name="district" class="text" onChange="getCity(' . "'" . 'findcity.php?district=' . "'" . '+this.value)">'; echo '<option value="">-- Select District --</option>'; while( $row = mysqli_fetch_array($result, MYSQLI_NUM)) { echo '<option value="' . $row[0] . '"'; // Check for stickyness: if ( isset( $_POST['district']) && ( $_POST['district'] == $row[0] )) echo ' selected="selected"'; echo " >$row[1]</option>"; } echo '</select>'; ?> </div> <div> <label for="city">City <img src="../images/required_star.png" alt="required" /> : </label> <input type="hidden" name="reg_locationid" id="reg_locationid" value="56" /> <div id="citydiv" style="position: relative; top: -14px; left: 130px; margin-bottom: -26px;"> <select name="city" class="text"> <option>-- Select City --</option> </select> </div> </div> this is, from my findcity.php page Code: [Select] <?php $districtId=$_GET['district']; require_once ('../includes/configaration.inc.php'); require_once( MYSQLCONNECTION ); $query="select city_id, city_name from city2 where district_id=$districtId"; $result=mysqli_query( $dbc, $query); echo '<select name="city" class="text"> <option>-- Select City --</option>'; while($row=mysqli_fetch_array($result, MYSQLI_NUM)) { echo '<option value="' . $row[0] . '"'; // Check for stickyness: if ( isset( $_POST['city']) && ( $_POST['city'] == $row[0] )) { echo ' selected="selected"'; //echo '<input type="hidden" name="city" value="' . $row[0] . '"'; } echo " >$row[1]</option>"; } echo '</select>'; ?> Hello How do I fetch a current visitors ip address, and turn it into a variable? The visitor should only be able to enter the same form once, so I want to compare the current visitor ip address with ip addresses in the database to achieve this. Best regards Morris i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers Is there a way to auto populate someone's city by zipcode? Also is it possible to find out their county as well? I have a form with PHP validation and also a mysqli query checking for duplicates in the database for mailing address and email address in mysql.
It works fine but the customers are adding spaces in the mailing address for example 111 mailing address A V E, 1 1 1 ma iling address A V E etc. and my sql query doesn't see that as an address that's a duplicate.
Their alslo adding email address like my@emailaddress.com and m.y@emailaddress.com, m.y.2@emailaddress.com etc to bypass that comparision also.
Is there anyway to stop this from happening?
i get this error Warning: current() [function.current]: Passed variable is not an array or object.. for this Code: [Select] $lastblock = current( ${"s".$row} ); print_r($lastblock); when i change to this it works.. Code: [Select] $lastblock = current( $s0 ); print_r($lastblock); The problem is i won't know the $row seeing as it is in a while loop. Solution? This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=359321.0 I am looking for the easiest way to get live data for the current temperature for various U.S. cities. I just need to capture the data and display on the page. Any recommendations? Greetings, Well i have a registration function in my website. User chooses his city of residence. Now all i need is to find the neighbouring city of the city he specifies while registering. This is required for the cities outside US and Canada [For these two we can use zip codes to find neighbouring cities.]. Is it possible to find neighbouring cities for cities of other countries?? Thanks I have a problem with the following code but i really don't see it: I try to populate the city textfield by the zipcode entered on the zipcode textfield function fillcitystate(controlname) { var zipstring = ""; xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "postcode.php?postcode=" + controlname.value, true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { var zipstring = xmlhttp.responseText; if (zipstring!="Error") { var ziparray = zipstring.split("|"); document.getElementById("test").innerHTML = ziparray[1]; } } } xmlhttp.send(null); } In postcode.php $returnval = "Error"; $postcode = $_GET['postcode']; $query = "SELECT * FROM city WHERE code='$postcode'"; $resultval = mysql_query($query); $rowcount = mysql_num_rows($resultval); if ($rowcount==1) { $row = mysql_fetch_array($resultval); $returnval = $row['code']."|".ucwords(strtolower($row['name']))."|".$row['province']; } else { } echo $returnval; When entering a zipcode, nothing happened so i decided to just echo the name of the city using the innerHTML. Still nothing happened, so i commented out all the php in my postcode.php and decided to just do: $postcode = $_GET['postcode']; echo $postcode; then it printed out: 'undefined' Can somebody point me out? Hi, I'm wanting to find rows whose date is within the next week of the current month of the current year. The format of the date is, for example: 2010-10-28 Any ideas guys? Thanks lots! Hi i have this drop down list current the year is 2010 and downwards but i want to change the list to 2010 upwards u can notice on the 50-- so shows current year minus so current is 2010 to 61 how can i change 2010 to 2030 or sunfin?? echo '<select name="year_of_birth">',"\n"; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { if($i == $thisYear) { $s = ' selected'; } else { $s=''; } echo '<option value="' ,$i, '"',$s,'>' ,$i, '</option>',"\n"; } echo '</select>',"\n"; Hey guys, is there any way to get the IP address of people accessing my website using PHP? I'm trying to get a statistics area to work for my website. If there isn't a way using PHP, what would be an application which can get the IP address? Thanks a lot, Noid I have problem with # char in address and jquery, or any address with #. When i put this code in my php: <a href="#" id="dialog_link" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-newwin"></span>Open Dialog</a> .. my link on that button is still same like link that i am on it, it do not add "#" in address, but if i, instead of href="#", put href="#some_text", that link shows nice, link.php#some_text, but without text in # it doesn't work :S Why is that happening, and how can i fix that? Okay, so I know how to get an IP address using $_SERVER['REMOTE_ADDR'], however, I need to get an IP a little different. How would I get the IP of the visitor on a remote site loading MY site using file_get_contents()? It just returns that remote websites server IP... :/ Thanks! Hello, Please let me know what is the wrong with the following lines of code. I am trying to find the MAC Address of the user who is logging. When I am running the code in localhost it is working. But the same code is not working when I upload it in the server. <?php function getMac(){ exec("ipconfig /all", $output); foreach($output as $line){ if (preg_match("/(.*)Physical Address(.*)/", $line)){ $mac = $line; $mac = str_replace("Physical Address. . . . . . . . . :","",$mac); } } return $mac; } $mac = getMac(); $mac = trim($mac); echo $mac; ?> Please help. Thanks a lot in advance. Regards & Thanks. Hey all, How can i get the current URL including any $_POST variables which arent visible? Thanks. HI There, I am using this type of code to self load a submitted form <form name = "testform" method = "post" action = "<?=$_SERVER['PHP_SELF']?>" onsubmit = "return check_data()" > Apart from using $_SERVER['PHP_SELF'] is there another way of determining the current URL within a script ? regards, Steven Matthews Hello i just spent my hour finding way to get XML attribute using PHP via URL i wanted to know is it possible or not like http://myurl.com/index.php?$xml=link1 link1 in my XML is some text can we get attribute like this via using URL on address bar Code: [Select] <?xml version="1.0" encoding="ISO-8859-1"?> <note> <link1>www.2advanced.com</link1> <link2>www.hotmail.com</link2> <link3>www.gmail.com</link3> <link4>www.twitter.com</link4> </note> |