脚本编写htaccess文件添加幻象未知字符导致500错误 [英] Script to write htaccess file adding phantom unknown character causing a 500 error

查看:151
本文介绍了脚本编写htaccess文件添加幻象未知字符导致500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个小工具,它允许管理员来管理,从管理的 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 \r\n";
    $htaccess_code .= "order allow,deny \r\n";
    }   
    if(!empty($block_ips)){
    $the_ips = explode(',',$block_ips);
        foreach($the_ips as $the_ip){ $htaccess_code .= "deny from ".trim($the_ip)." \r\n"; }
    }   
    if(!empty($allowed_ips)){
    $the_ips = explode(',',$allowed_ips);
        foreach($the_ips as $the_ip){ $htaccess_code .= "allow from ".trim($the_ip)." \r\n"; }
        }   
    $htaccess_code .= "allow from all \r\n";
    $htaccess_code .= " \r\n";

产生:

#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 IP\r\n";
    $htaccess_code .= "order allow,deny\r\n";
    }   
    if(!empty($block_ips)){
    $the_ips = explode(',',$block_ips);
        foreach($the_ips as $the_ip){ $htaccess_code .= "deny from ".trim($the_ip)."\r\n"; }
    }   
    if(!empty($allowed_ips)){
    $the_ips = explode(',',$allowed_ips);
        foreach($the_ips as $the_ip){ $htaccess_code .= "allow from ".trim($the_ip)."\r\n"; }
        }   
    $htaccess_code .= "allow from all\r\n";
    $htaccess_code .= "\r\n";

我不知道在哪里何去何从?任何援助将大大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

皮特

这篇关于脚本编写htaccess文件添加幻象未知字符导致500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆