4

I'm working on a website for parkos where clients can make reservations with there email but some clients use a plus sign in their email.

for example:

test+parkos@gmail.com

Now if for example clients wanted to see their reservations I'm creating a get request in the url and you would get something like this:

http://test.com/reservations/?email=test+parkos@gmail.com&number=GH76G

after that I'm trying to retrieve the email and echo it:

$email = request()->input('email');
{{!! $email!!}}

Than If I try to view on it my webpage this is what I get:

test parkos@gmail.com

The + sign is gone and I was wondering if there is a way to keep the + sign.

3 Answers3

3

Url is wrong because + sign has its own meaning according to CGI standard. It means a whitespace.

Right url shold be

http://test.com/reservations/?email=test%2Bparkos@gmail.com&number=GH76G

As explained in URLs and plus signs

+ becomes %2B
space becomes %20

In order to avoid further mistakes, best practice is encoding text before using it in a URL like this:

$url = "http://" . $domain . "/whatever.php?text=" . urlencode($text);
Community
  • 1
  • 1
1

Send decoded url and get $_GET['email']

urlencode('test+email@gmail.com');
Basant Rules
  • 785
  • 11
  • 8
  • $url = "http://domain/index.php?email=".urlencode($path); when you get the email then you will get email with + sign – Basant Rules Sep 14 '16 at 17:38
1

Space characters are encoded as "+" in application/x-www-form-urlencoded key-value pairs.

The RFC-1866 (HTML 2.0 specification), paragraph 8.2.1. subparagraph 1. says: "The form field names and values are escaped: space characters are replaced by `+', and then reserved characters are escaped").

Thus, while decoding the URLs, pluses are decoded back to spaces. For example, in your URL.

If you construct this URL using PHP, please call urlencode() on each of the key/value pairs, don't concatenate strings unencoded.

http://test.com/reservations/?email=test+parkos@gmail.com&number=GH76G

email will become

test parkos@gmail.com

to prevent it, make sure that the '+' characters in the URL are percent-encoded correctly, so the correct URL should be the following:

http://test.com/reservations/?email=test%2Bparkos@gmail.com&number=GH76G
Maxim Masiutin
  • 3,991
  • 4
  • 55
  • 72