-1

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
Community
  • 1
  • 1
mina
  • 141
  • 1
  • 10
  • So why isn't Subjectstr urlencoded as well? – Mark Baker Jan 01 '17 at 14:12
  • i know it must be encoded , but i knew that after 8 hours of troubleshooting , so exactly i want to know why spaces in url prevent get method from automatically decoding – mina Jan 01 '17 at 14:13
  • i wrote above, that BodyStr attribute is encoded via urlencode function – mina Jan 01 '17 at 14:15
  • All parameters need to be URL-encoded. Space isn't allowed in query strings, so if there's an unencoded space in `SubjectStr`, it will break the URL there. – Barmar Jan 01 '17 at 14:16
  • both of the links are worked fine , but the first link prevented the GET method from decoding automatically , – mina Jan 01 '17 at 14:17
  • That means it didn't work fine. – Barmar Jan 01 '17 at 14:18
  • didn't work fine means that PHP will trigger error or the rest of the attributes will be stripped after the wrong attribute which isn't happened – mina Jan 01 '17 at 14:19

1 Answers1

1

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.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • the server saw the rest of the link , and if you want to show that , i can write down the result of printing Get method attributes – mina Jan 01 '17 at 14:20
  • your first part of answer is correct , but you didn't mention why GET stopped decoding the url at the attribute which has spaces – mina Jan 01 '17 at 14:22
  • I've added an explanation based on the HTTP protocol. – Barmar Jan 01 '17 at 14:24
  • as you mentioned , if the server never sees the BodyStr Parameter , so how can i still dealing with the parameters after the one which has spaces ? – mina Jan 01 '17 at 14:25
  • please , write var_dump($url) , and you will see all the attributes and the server saw all of them – mina Jan 01 '17 at 14:27
  • `var_dump($url)` is on the client, it doesn't tell you what the server sees. – Barmar Jan 01 '17 at 14:28
  • Use `var_dump($_GET)` on the server to see what it receives. – Barmar Jan 01 '17 at 14:29
  • I put that in the answer. Change the spaces in `SubjectStr` to `+`. That's the URL-encoding of space. – Barmar Jan 01 '17 at 14:30
  • already i did that and i told you that the variables are Array ( [me] => ahmed [y] => 1 [clientid] => 55 [default] => 1 [Subjectstr] => Email From Contactuspage [BodyStr] => %3Chtml%3E%3Cbody%3E%3Ctable+rules%3D%22all%22+style%3D%22border-color%3A+%23666%3B%22+cellpadding%3D%2210%22%3E%3Ctr+style%3D%27background%3A+%23eee%3B%27%3E%3Ctd%3E%3Cstronstrong%3Ephone%3A%3C%2Fstrong%3E+%3C%2Ftd%3E%3Ctd%3E++%3C%2Ftd%3E%3C%2Ftr%3E%3Ctr%3E%3Ctd%3E%3Cstrong%3EEmail%3A%3C%2Fstrong%3E+%3C%2Ftd%3E%3Ctd%3E++%3C%2Ftd ) i striped the full answer because of the comment length – mina Jan 01 '17 at 14:31
  • It looks like you're URL-encoding `BodyStr` twice. – Barmar Jan 01 '17 at 14:32
  • no , this is the result of printing the GET method and BodyStr isn't decoded automatically by GET because of subject spaces attribute – mina Jan 01 '17 at 14:33
  • That's not how things work. The decoding of one parameter is not affected by another parameter. Something is double-encoding BodyStr. – Barmar Jan 01 '17 at 14:35
  • if you have an email , i can send you the 3 lines of the script . iam appreciating your efforts but still i don't have a real reason sir – mina Jan 01 '17 at 14:36
  • and when i removes the spaces of subject paramters , the body decoded automatically and if i left the spaces, the attributes didn't decoded – mina Jan 01 '17 at 14:38