How long can the url request argument be?

http://site.com/?status=4387hg843hg89473gh87934h89g734hg8973hg9873hg8973h4987g3h489g7h89h849g5

What is the maximum size of status that PHP can read?

I want to send error / success messages during registration or registration, and the only way to do this is to redirect to the URL and add the messages as arguments for that URL.

as:

 <?php $errors = array( 1 => 'Password must have between 6 and 20 characters', 2 => 'User name must contain only AZ, az and 0-9 characters', 3 => 'Captcha code does not match', ); $errors = base64_encode(serialize($errors)); header("Location: http://www.example.com/?status={$errors}"); die(); 

(if you know different ways to do this, tell me;)

+7
source share
3 answers

According to RFC2616 Section 3.2.1 :

The HTTP protocol does not place any a priori limit on the length of the URI. Servers MUST be able to process the URIs of any resource they serve, and SHOULD be able to process the URIs of unlimited if they provide GET-based forms that can generate such URIs. the server MUST return 414 (Request-URI Too long) if the URI is longer than the server can process (see section 10.4.15).

With this in mind, many browsers do not allow infinite URLs. For example, Internet Explorer has a limit of 2083 characters .

In your case, I would suggest using a session variable to store the error, and delete it after displaying it.

File that creates errors:

 <?php $errors = array( 1 => 'Password must have between 6 and 20 characters', 2 => 'User name must contain only AZ, az and 0-9 characters', 3 => 'Captcha code does not match', ); session_start(); $_SESSION['errors'] = $errors; header("Location: http://www.example.com/"); die(); 

Another page:

 <?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']); } 
+9
source

It depends more on the user browser than on everything else. For example, Internet Explorer does not support URLs with more than 2083 characters. PHP should do a great job of (and well past) this limitation. Avoiding base64_encode (which is optional) will help. Use urlencode instead (assuming you don't pass any binary data).

I'm sure people would like to help with different ways of doing this, but you will need to provide more code.

+1
source

My suggestion is to use HTTP POST instead of HTTP GET

+1
source

All Articles