Reacen
Reacen

Reputation: 2370

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 on 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?

Upvotes: 0

Views: 323

Answers (3)

Artefacto
Artefacto

Reputation: 97835

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.

Upvotes: 1

Pheonix
Pheonix

Reputation: 6052

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

Upvotes: 1

Quentin
Quentin

Reputation: 944195

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.

Upvotes: 1

Related Questions