我写一个小工具,它允许管理员来管理,从管理的 htaccess文件
。该脚本将呈现为在的htaccess code
正在生成它抛出一个500错误的空间的幻影符。
I am writing a widget that allows admin to manage the htaccess file
from administration. The script is adding a phantom character rendered as a space in the htaccess code
being generated which is throwing a 500 error.
# block/allow users by ip
if(!empty($block_ips) || !empty($allowed_ips)){
$htaccess_code .= "#Block-Allow users by IP rn";
$htaccess_code .= "order allow,deny rn";
}
if(!empty($block_ips)){
$the_ips = explode(',',$block_ips);
foreach($the_ips as $the_ip){ $htaccess_code .= "deny from ".trim($the_ip)." rn"; }
}
if(!empty($allowed_ips)){
$the_ips = explode(',',$allowed_ips);
foreach($the_ips as $the_ip){ $htaccess_code .= "allow from ".trim($the_ip)." rn"; }
}
$htaccess_code .= "allow from all rn";
$htaccess_code .= " rn";
#Block-Allow users by IP
order allow,deny
deny from 000.000.111.111
deny from 444.444.555.555
allow from 444.433.555.555
allow from 010.000.111.111
allow from all
有在每一行的末尾的空间/幻像字符。如果在500错误我删除了空间编辑度过FTP和保存 htaccess文件
再刷新页面的所有ID罚款。
There is a space/phantom character at the end of each line. If during the 500 error I delete the space editing live through FTP and save the htaccess file
and then refresh the page all id fine.
如果我删除了code中的空间下方,那么C发生500错误运行$ C $。
If I remove the space in the code as below and then run the code the 500 error occurs.
# block/allow users by ip
if(!empty($block_ips) || !empty($allowed_ips)){
$htaccess_code .= "#Block-Allow users by IPrn";
$htaccess_code .= "order allow,denyrn";
}
if(!empty($block_ips)){
$the_ips = explode(',',$block_ips);
foreach($the_ips as $the_ip){ $htaccess_code .= "deny from ".trim($the_ip)."rn"; }
}
if(!empty($allowed_ips)){
$the_ips = explode(',',$allowed_ips);
foreach($the_ips as $the_ip){ $htaccess_code .= "allow from ".trim($the_ip)."rn"; }
}
$htaccess_code .= "allow from allrn";
$htaccess_code .= "rn";
我不知道在哪里何去何从?任何援助将大大AP preciated。
I am not sure where to go from here... any assistance would be greatly appreciated.
皮特
解决的问题:
虽然我很高兴已经了解了 PHP_EOL
并没有做出对整个剧本的改变......它并没有解决问题。在code是正确的。这个问题是我在这个问题显示测试的IP地址。
While I am glad to have learned about PHP_EOL
and did make the change on the entire script... it did not resolve the issue. The code was correct. The issue was in the IP addresses I tested with shown in the question.
没有完全达到速度的IP地址我想任何逗号分隔的4个数字会做一个测试?显然不是。我改变了测试IP地址已知IP地址和脚本工作的罚款。
Not being fully up to speed in IP Addresses I figured any comma separated 4 digits would do for a test... apparently not. I changed the test IPs to known IPs and the script worked fine.
虽然一个简单的解决方案,我认为这是值得分享的。
Though a simple solution I thought it was worth sharing.
感谢所有的输入... pciated多少AP $ P $
Thanks for all the input ... much appreciated
皮特