如何防止 URL 出现空格?没有任何方法有效

发布于 2024-11-06 11:22:40 字数 855 浏览 4 评论 0原文

我在这方面遇到了很多麻烦,$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

水染的天色ゝ 2024-11-13 11:22:40

urlencode() 可以工作。

确保将地址用引号引起来,并且它位于一行上:

<form ... action="reports1.php?report=2011-05-08%20Brazil%20Botulism">

urlencode() will work.

Make sure you wrap the address in quotes, and it is on one line:

<form ... action="reports1.php?report=2011-05-08%20Brazil%20Botulism">
甜点 2024-11-13 11:22:40

使用 PHP 的 trim() 函数删除字符串开头和结尾中不需要的空格。

Use PHP's trim() function to remove unwanted whitespace in the beginning and the end of a string.

忆梦 2024-11-13 11:22:40

好吧,你不需要原始它,

echo "hi";

会和你一起工作,如果你上面的代码只有一个问题,你对你的表单使用 $_POST 方法而不是 $_GET

表单onsubmit =“返回验证(此)”
方法=“发布”操作=
应该是

一个非常好的和简单的调试代码,可以帮助你检索所有 $_GET 并将它们分配给变量,

使用

foreach($_GET as $var=>$val)$var=$val;

此代码将获取所有发布的获取并将它们分配给具有自己名称的变量,($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

form onsubmit="return validate(this)"
method="post" action=
should be

a very nice and easy debugin code that can help u is retriving all $_GETs and assign them to vars,

with

foreach($_GET as $var=>$val)$var=$val;

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文