why GET method didn't decode attributes in case url has attributes have spaces?

84 views Asked by At

kindly I have two links, when using both of the links in another page, the first link is decoded automatically by GET Method and the second didn't. the problem is that if there is a space in any attribute, the get don't decode automatically the URL and if there are no spaces, the get automatically decoding the URL which is the correct behaviour tip : the only encoded attribute is BodyStr and encoded via URLENCODE PHP function.

another tip: the difference between both is the space in subjectStR Attribute

I want to know why spaces in URL prevent GET Global Variable from automatically decoding all the attributes

  $message=urlencode($message);
        http://localhost/test4.php?me=ahmed&y=1&clientid=55&default=1&Subjectstr=**Email From Contactuspage`**&BodyStr=$message
    
        http://localhost/test4.php?me=ahmed&y=

1&clientid=55&default=1&Subjectstr=**EmailFromContactuspage**&BodyStr=$message
1

There are 1 answers

14
Barmar On

Space isn't allowed in URL query strings. If you put an unencoded space in SubjectStr, the URL ends at that point, so the server never sees the BodyStr parameter.

You need to URL-encode SubjectStr. Replace the spaces with + or %20.

$message=urlencode($message);
$url = "http://localhost/test4.php?me=ahmed&y=1&clientid=55&default=1&Subjectstr=Email+From+Contactuspage&BodyStr=$message"

The reason why it stops at space is because of the HTTP protocol. The client sends:

GET <url> HTTP/1.1

This request line is parsed by looking for the space between the URL and the HTTP version token. If there's a space in the URL, that will be treated as the end of the URL.