<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Update .htaccess with Dynamic DNS IP Address to Prevent Password Protection</title>
	<atom:link href="http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/feed/" rel="self" type="application/rss+xml" />
	<link>http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/</link>
	<description>Thoughts of a Software Engineer.</description>
	<lastBuildDate>Thu, 02 Feb 2012 22:08:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: ray</title>
		<link>http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/comment-page-1/#comment-16254</link>
		<dc:creator>ray</dc:creator>
		<pubDate>Mon, 25 Apr 2011 17:00:13 +0000</pubDate>
		<guid isPermaLink="false">http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/#comment-16254</guid>
		<description>I&#039;ve having exactly the same problem as yours, and I&#039;m updating my dynamic IP manually for a few years using FTP lol.

Your great blog enlightened me, but sadly my webhost doesn&#039;t allow shell_exec so I wrote a simple perl script instead, hope reader here find it useful.

My perl doing exactly the same as your php, however, instead of reading a live .htaccess file, my perl read from a template instead, of course, if you assign a live .htaccess as a template, it works as well. 

Once it found the template file, it looks for any line(s) contains the word @@@DYNAMIC@@@ and then replace it with a &lt;B&gt;new line&lt;/B&gt; below

allow from 1.2.3.4

The perl script is already running on my shared web hosting account :)

&lt;pre class=&quot;brush: perl;&quot;&gt;
#!/usr/bin/perl

$htaccess = &quot;/volume1/web/test/.htaccess&quot;;
$template = &quot;/volume1/web/test/template&quot;;

# get ip address
$result=`host myhome.somedomain.com`;
@sp = split(/ /,$result);
$size = @sp;
$ip = $sp[$size-1];

open(TEMPLATE, $template) &#124;&#124; die(&quot;Could not open file!&quot;);
@raw_data=;
close(TEMPLATE);

open(NEW, &quot;&gt;$htaccess&quot;) &#124;&#124; die(&quot;Could not create file!&quot;);

foreach $line (@raw_data){
	if($line =~ /\@\@\@DYNAMIC\@\@\@/){
		print NEW &quot;allow from $ip\n&quot;;
	}else{
		print NEW $line;
	}
}

close(NEW);
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I&#039;ve having exactly the same problem as yours, and I&#039;m updating my dynamic IP manually for a few years using FTP lol.</p>
<p>Your great blog enlightened me, but sadly my webhost doesn&#039;t allow shell_exec so I wrote a simple perl script instead, hope reader here find it useful.</p>
<p>My perl doing exactly the same as your php, however, instead of reading a live .htaccess file, my perl read from a template instead, of course, if you assign a live .htaccess as a template, it works as well. </p>
<p>Once it found the template file, it looks for any line(s) contains the word @@@DYNAMIC@@@ and then replace it with a <b>new line</b> below</p>
<p>allow from 1.2.3.4</p>
<p>The perl script is already running on my shared web hosting account :)</p>
<pre class="brush: perl;">
#!/usr/bin/perl

$htaccess = "/volume1/web/test/.htaccess";
$template = "/volume1/web/test/template";

# get ip address
$result=`host myhome.somedomain.com`;
@sp = split(/ /,$result);
$size = @sp;
$ip = $sp[$size-1];

open(TEMPLATE, $template) || die("Could not open file!");
@raw_data=;
close(TEMPLATE);

open(NEW, "&gt;$htaccess") || die("Could not create file!");

foreach $line (@raw_data){
	if($line =~ /\@\@\@DYNAMIC\@\@\@/){
		print NEW "allow from $ip\n";
	}else{
		print NEW $line;
	}
}

close(NEW);
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

