0

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?

1
  • You should ask the company that makes the request why you need to URLENCODE their URL. Commented Sep 7, 2011 at 14:35

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

You go to the PHP manual and search for urlencode, which will show you the urlencode() function.
Where to encode? My variables are empty... That will not work
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.