开发者

URLENCODING in a url problem

I'm using a service where about each hour their server is contacting mine like this:

/check.php?id=1&name=anonyme&country=us

So I pick up the information like this:

$id = @$_GET['id'];
$name = @$_GET['name'];
$country = @$_GET['country'];

Great, everything works just fine. But when the name has a space on it let's say:

/check.php?id=1&name=MR Anonymous&country=us

Then in php I can only pickup the ID and the First part on the name which is 'MR'. And I can't get the other values (country, etc..) they stay empty because of that space.

I have contacted the company that sends this information, I told them maybe it's their problem and they said no, I just have to URLENCODE my URL..

I still think it's their problem not mine, because when I see the Apache logs I see a space 开发者_如何学Pythonon their URL, they should fix that space. (Because when I use the same URL in any browser, that space turn into %20, that isn't the case with the company)

Is it my problem? Or their problem? How to fix it if it's mine?


If they are making those requests to your server (and you have no control over those requests), then it's definitely not you at fault.

Spaces in URIs are prohibited. Apache does allow them, but PHP gets confused and takes the part after the space as the protocol.

You can accomodate this problem by appending $_SERVER['SERVER_PROTOCOL'] to $_SERVER['QUERY_STRING'], removing everything after the last space and then parsing this URL (see parse_url and parse_str). The best, however, would be they fixing their requests.


Raw spaces are not allowed in URIs (even though some clients and some servers can error recover when asked to deal with them).

You do need to urlencode the data.


I think they (the other server) will need to urlencode() the data before sending to your server, and then you will urldecode() it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜