如何防止 URL 出现空格?没有任何方法有效
我在这方面遇到了很多麻烦,$report 在 URL 中的空格处被破坏,我已经尝试解决这个问题几天了,但没有任何效果。
<form onsubmit="return validate(this)" method="post" action=
<?
echo "\"reports1.php?report=";
echo rawurlencode($report);
echo "\"";
?>
>
……
if(isset($_GET['report'])){
$report = $_GET['report'];
echo "<script>alert('All reports will be appended to \"".$report."\" until GET and POST data are cleared.')</script>";
}
elseif($country != NULL){
$report = $date." ".$country." ".$topic;
}
elseif($country == NULL){
$report = $date." ".$region." ".$topic;
}
这
是一个例子; $report 被 $_GET 标记为
“2011-05-08”, 即使它应该是 但 $_POSTING 为“2011-05-08 巴西肉毒杆菌中毒”
“reports1.php?report=2011-05-08”
I am having a lot of trouble with this, $report is breaking at the space in the URL, and I Have been trying to fix this problem for a couple of days now, and nothing is working.
<form onsubmit="return validate(this)" method="post" action=
<?
echo "\"reports1.php?report=";
echo rawurlencode($report);
echo "\"";
?>
>
...
if(isset($_GET['report'])){
$report = $_GET['report'];
echo "<script>alert('All reports will be appended to \"".$report."\" until GET and POST data are cleared.')</script>";
}
elseif($country != NULL){
$report = $date." ".$country." ".$topic;
}
elseif($country == NULL){
$report = $date." ".$region." ".$topic;
}
...
Here is an example; the $report is getting $_GET'ted as
"2011-05-08 ",
even though it should be
but it is $_POSTING as "2011-05-08 Brazil Botulism"
"reports1.php?report=2011-05-08 "
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
urlencode()
可以工作。确保将地址用引号引起来,并且它位于一行上:
urlencode()
will work.Make sure you wrap the address in quotes, and it is on one line:
使用 PHP 的
trim()
函数删除字符串开头和结尾中不需要的空格。Use PHP's
trim()
function to remove unwanted whitespace in the beginning and the end of a string.好吧,你不需要原始它,
echo "hi";
会和你一起工作,如果你上面的代码只有一个问题,你对你的表单使用 $_POST 方法而不是 $_GET
一个非常好的和简单的调试代码,可以帮助你检索所有 $_GET 并将它们分配给变量,
使用
此代码将获取所有发布的获取并将它们分配给具有自己名称的变量,($report 而不是 $_GET['report '];) 你可以在所有 $_post 和 $_get 上使用这个函数来知道问题到底出在哪里:)..
希望它有帮助
well you dont need to raw it,
echo "hi";
will work fine with ya, in case of ur code above there is only one problem that u use $_POST method for ur form not $_GET
a very nice and easy debugin code that can help u is retriving all $_GETs and assign them to vars,
with
this code wil get all posted gets and assign them to variables with there own name, ($report instead of $_GET['report'];) u can use this function on all $_post and $_get to know where is exactly the problem :)..
hope it helps