如何清理 PHP 中包含“;”的字符串回声”? (我有充分的理由)
我将这个案例变成了一个简单的 PHP 页面,可以自行提交。我的问题是,我正在提交田径比赛结果,其中一个女孩的名字是 Echo……一个可爱的名字。
我提交的问题文本是: 撑竿跳高 - Rachel Simons,Tow,8-6;埃科·威尔逊,Cit,8-0;莫莉·兰德尔,拖车,7-0;
所以你会看到一个分号,后面跟着空格,然后是 Echo...
提交后,它显示: 不支持 POST 到 /results/test.php
最终目标是将其与其他一些信息一起保存到数据库中,并有一个搜索页面来查找它并简单地在屏幕上打印出完整结果。我删除了所有数据库内容以将其归结为这一错误。我的意思是,我可以故意拼错她的名字,但总有办法解决这个问题,对吗???
这是测试 PHP 文件。
<html>
<head>
<title>title</title>
</head>
<body>
<?php
echo "<h3>Edit meet info below</h3>";
echo "<form action=\"test.php\" method=\"post\" id=\"submitForm\">";
echo "Full Results:<br/><textarea NAME=\"results\" id=\"results\" rows=\"20\" cols=\"80\" MAXLENGTH=\"8191\"></textarea><br/><br/>";
echo "<input type=\"submit\" name=\"submitMeet\" value=\"Submit\">";
echo "</form>";
?>
</body>
</html>
I turned this case into a simple PHP page that submits to itself. My issue is that I am submitting track meet results and one of the girl's names is Echo...a lovely name.
The problem text I'm submitting is:
Pole vault - Rachel Simons, Tow, 8-6; Echo Wilson, Cit, 8-0; Molly Randall, Tow, 7-0;
So you see a semicolon followed by white space followed by Echo...
After submitting, it says:
POST to /results/test.php not supported
The end goal is to save it to a database along with some other info and have a search page to find it and simply print out the full result on the screen. I stripped out all my database stuff to get it down to this one error. I mean, I can intentionally mis-spell her name, but there's gotta be a way around this, right???
Here's the test PHP file.
<html>
<head>
<title>title</title>
</head>
<body>
<?php
echo "<h3>Edit meet info below</h3>";
echo "<form action=\"test.php\" method=\"post\" id=\"submitForm\">";
echo "Full Results:<br/><textarea NAME=\"results\" id=\"results\" rows=\"20\" cols=\"80\" MAXLENGTH=\"8191\"></textarea><br/><br/>";
echo "<input type=\"submit\" name=\"submitMeet\" value=\"Submit\">";
echo "</form>";
?>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来你有一些蹩脚的安全系统(也许
mod_security
?),它正在扫描请求并拒绝那些看起来可能存在风险的请求。您必须询问您的网络主机或其他人是否可以禁用它。没有 PHP 函数可以任意拒绝基于任意文本组合的 POST 请求。 (至少在这种情况下不是)
It sounds like you have some lame security system (Perhaps
mod_security
?) that is scanning the requests and rejecting ones that look like they might be a risk.You will have to ask your web host or something if they can disable it. There is NO PHP function that will arbitrarily reject a POST request based on any combination of text. (At least, not in this case)
你只需要让 Echo 改变她的名字......名字......名字。
不过说真的,看看 webdestroya 的建议。如果失败,我认为快速而肮脏的解决方案是更改用于分隔 POST 请求中的名称的分隔符,然后在收到分隔符后将该分隔符更改回分号。所以你会发布类似这样的内容:
然后这样做:
如果你不想在输入结果时手动键入分隔符,你可以编写一个小的 JavaScript 来自动转换分号,例如在提交时。
You'll just have to get Echo to change her name... name... name.
Seriously though, look into what webdestroya suggested. If that fails, I think the quick-and-dirty solution would be to change the delimiter you use to separate the names in the POST request, and then change that delimiter back to semicolons after it is received. So you would POST something like this:
Then do this:
If you don't want to manually type the delimiter when entering results, you could write a small JavaScript to convert the semicolons automatically, e.g. on submit.