PHP 可以读取的 status 的最大大小是多少?

我想在登录或注册时传递错误/成功消息,我能做到这一点的唯一方法是重定向到 URL 并将消息作为参数附加到该 URL。

喜欢:

<?php

 $errors = array(
   1 => 'Password must have between 6 and 20 characters',
   2 => 'User name must contain only A-Z, a-z and 0-9 characters',
   3 => 'Captcha code does not match',
 );

 $errors =  base64_encode(serialize($errors));

 header("Location: http://www.example.com/?status={$errors}");
 die();

(如果您知道这样做的不同方法,请告诉我;)

最佳答案

根据 RFC2616 Section 3.2.1 :



话虽如此,许多浏览器不允许无限长度的 URL。例如,Internet Explorer 有一个 limit of 2,083 characters

在您的情况下,我建议使用 session 变量来存储错误,并在显示后将其删除。

产生错误的文件:

<?php

 $errors = array(
   1 => 'Password must have between 6 and 20 characters',
   2 => 'User name must contain only A-Z, a-z and 0-9 characters',
   3 => 'Captcha code does not match',
 );

 session_start();
 $_SESSION['errors'] = $errors;

 header("Location: http://www.example.com/");
 die();

另一个页面:
<?php

 session_start();

 if ( ! empty($_SESSION['errors']) )
 {
   // Do something with the errors.

   // Remove the errors from the session so they don't get displayed again later.
   unset($_SESSION['errors']);
 }

关于php - URL 查询参数可以有多长?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6618082/

10-14 15:03
查看更多