Why does a html form variable posting gets truncated on a php receive ?

I have a HTML form which send a variable to my server side php code via a javascript ajax function. like
var url = "search.php" + "?strsrch=" + s + "&choice=" + c;
var mygetrequest = ajaxRequest(url);
The problem is when the variable s or c contains a # in between, the php program truncates the string on that #. Is that something normal in php ? I can not understand the situation, I am not a very experienced coder of php though.
Thanks for any help in advance.

That’s because you didn’t escape your strings. Any special character will mess it up.

var url = "search.php" + "?strsrch=" + escape(s) + "&choice=" + escape(c);

(Imagine what would happen if s was "test&hackvar=13" and you didn’t escape it. It would result in a new variable being injected into your url)

One Response to “Why does a html form variable posting gets truncated on a php receive ?”

  • Jim J says:

    That’s because you didn’t escape your strings. Any special character will mess it up.

    var url = "search.php" + "?strsrch=" + escape(s) + "&choice=" + escape(c);

    (Imagine what would happen if s was "test&hackvar=13" and you didn’t escape it. It would result in a new variable being injected into your url)
    References :

Leave a Reply