Created
October 26, 2012 19:32
-
-
Save jasontucker/3960947 to your computer and use it in GitHub Desktop.
Update single ip address from dyndns into the allowed IP address of InfiniteWP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Install this file in the infiniteWP folder, name it something | |
// obscure then have cron run ever 3 mins to update the db to the latest IP. | |
// Add the following to cron, this will update the ip address every 3 minutes. | |
// | |
// */3 * * * * /usr/local/bin/php /home/username/infinitewp/updateip.php | |
// What is your dyndns hostname? | |
$dyndns = "myhost.dyndns-remote.com"; | |
// Include the config.php file from InfiniteWP | |
require_once('config.php'); | |
// Assign the variables from config.php | |
$database = $config['SQL_DATABASE']; | |
$host = $config['SQL_HOST']; | |
$username = $config['SQL_USERNAME']; | |
$password = $config['SQL_PASSWORD']; | |
$table_prefix = $config['SQL_TABLE_NAME_PREFIX']; | |
//Table we're updating | |
$table = "allowed_login_ips"; | |
// Retrieve the ip address of our dyndns | |
$current_ip_address = gethostbyname($dyndns); | |
// Connect to the DB | |
$con = mysql_connect($host,$username,$password); | |
if (!$con){ | |
die('Could not connect: ' . mysql_error()); | |
} | |
// Select the Database | |
$db_selected = mysql_select_db($database, $con); | |
if (!$db_selected){ | |
echo mysql_errno($con) . ": " . mysql_error($con). "\n"; | |
} | |
// Build our update query | |
$sql = "UPDATE $table_prefix$table SET IP = '$current_ip_address'"; | |
// Run the query | |
mysql_query($sql, $con); | |
if (!$con){ | |
echo mysql_errno($con) . ": " . mysql_error($con) . "\n"; | |
} | |
// Close our DB connection | |
mysql_close($con); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment