0

I have a bunch of integers which act as ID's within an ArrayList in my Android application.

This list of id's can be of any amount ranging from 0 - x. These id's are to identify players in a match. What I want is to send data to the web service, telling it that players 1,2 and 3 are on team 1 and players 4,5 and 6 are on team 2.

How best can I construct the URL with the above and how do I properly "expect" and "intercept" these parameters on the server side? I am using PHP.

So far I can think of the following:

 $p1 = $_GET['p1'];
 $p2 = $_GET['p2'];
 $p3 = $_GET['p3'];

But as you can probably guess, that's really bad as I don't know how many people will be in team 1 and how many people in team 2. And further...how to seperate them.

Any ideas?

Bobot
  • 1,118
  • 8
  • 19
Subby
  • 5,370
  • 15
  • 70
  • 125

1 Answers1

3

You can do a simple list of players in each teams :

// $_GET['team1'] = '1,2,3';
$team1 = $_GET['team1'];
$team1 = explode(',', $team1);

// $_GET['team2'] = '4,5,6';
$team2 = $_GET['team2'];
$team2 = explode(',', $team2);

Then you have an array per team, containing the players id.

Hope it helped !

EDIT:

Care of query maxlength here is a link :

Please note that PHP setups with the suhosin patch installed will have a default limit of 512 characters for get parameters. Although bad practice, most browsers (including IE) supports URLs up to around 2000 characters, while Apache has a default of 8000.

To add support for long parameters with suhosin, add suhosin.get.max_value_length = in php.ini

Bobot
  • 1,118
  • 8
  • 19
  • Ah that's brilliant! I shall try that out! Does that mean that I have to delimit the id's with a comma? – Subby Jul 17 '14 at 19:30
  • ye, you just have to use an url like : `http://myserver/myscript.php?team1=1,2,3&team2=4,5,6`. I don't know how you store your players, but if it's in an `ArrayList` like for your **ID**'s, you can just [implode()](http://php.net/manual/en/function.implode.php) it. I guess you want to to it with android, so .. i found [that answer](http://stackoverflow.com/a/11248306/3799829) ;) – Bobot Jul 17 '14 at 22:34