Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************************************************************/
- /* Description: This snippet is provide simple way to help user display San Francisco Bay Area . */
- /* suggestions for different city locations across the country. */
- /* There are 1 steps in this snippet. For information, please visit IP2Location tutorial page at: */
- /* https://www.ip2location.com/tutorials/display-san-francisco-bay-area */
- /****************************************************************************************************************/
- /* You can obtain free IP2Location LITE database for IPv4 at https://lite.ip2location.com */
- /* You can obtain free Bay Area CSV file form Github at https://github.com/chrislim2888/bay-area */
- <?php
- if(isset($_POST['ip_address'])){
- $conn = new mysqli("localhost", "root", "", "sf_bay");
- if (mysqli_connect_errno()) {
- echo "<p>Connection failed:".mysqli_connect_error()."</p>\n";
- }
- $ip = $_POST['ip_address'];
- $sql = "SELECT db.country_name, db.region_name, db.city_name, b.bay_area
- FROM ip2location_db3 db, bay_area b
- WHERE db.region_name = b.region_name
- AND db.country_code = b.country_code
- AND inet_aton('$ip') <= db.ip_to
- limit 1";
- $result = mysqli_query($conn, $sql) or die (mysqli_error($conn));
- mysqli_close($conn);
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>San Francisco Bay Areas</title>
- <style>
- th, td{
- padding-right: 15px;
- text-align: left;
- }
- </style>
- </head>
- <body>
- <h2>San Francisco Bay Areas</h2>
- <p>Enter an IP address to extract bay area information</p>
- <form name="query" method="post">
- <label for="address">IP here: </label>
- <input type="text" name="ip_address" id="ip_address" size="40" value="<?= isset($_POST['ip_address']) ? htmlspecialchars($_POST['ip_address']) : '' ?>">
- <button type="submit">Run</button>
- </form>
- <br/>
- <table>
- <tr>
- <th>Country</th>
- <th>Region</th>
- <th>City</th>
- <th>Bay Area</th>
- </tr>
- <?php
- if (isset($ip)){
- while ($row = mysqli_fetch_assoc($result)){
- $country = $row['country_name'];
- $region = $row['region_name'];
- $city = $row['city_name'];
- $bay = $row['bay_area'];
- echo "<tr>";
- echo "<td>".$country."</td>";
- echo "<td>".$region."</td>";
- echo "<td>".$city."</td>";
- echo "<td>".$bay."</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement