I am a beginner java and php I must pass a string variable from Java client to php server using WebView
Is what I am doing right?
In java side:
String Coords=CoordsString;
String PHPPagePath="http://10.0.2.2/ReceiveLocation.php?Coords=" + CoordsString";
and on the php side: ReceiveLocation.php
<?php
include('ConnectionFunctions.php');
Connection();
$x=$_GET['Coords'];
GetCoords($x);
function GetCoords($x)
{
echo $x;
}
?>
Is this the right way to pass the parameter Coords from Java Client to PHP Server Function?
To pass a parameter to PHP using the URL of the page, just append ?key=value
to the URL, where key
is the parameter key (i.e. the name) and value
is its value (i.e. the data you are trying to transfer), and then in the PHP script you can retrieve the parameter like this:
<?php
echo 'I have received this parameter: '.$_GET['key'];
?>
replacing 'key'
with the actual name of the parameter.
This is the way PHP reads HTTP GET variables. See this for more information: http://www.php.net/manual/en/reserved.variables.get.php
Please, be careful when accepting variables from outside: they have to be "sanitized", expecially if they are going to be used in database queries or printed in the HTML page.
Modify your code as following
Java code:
String Coords=CoordsString;
String PHPPagePath="http://10.0.2.2/ReceiveLocation.php?Coords=10";
PHP code:
<?php
include('ConnectionFunctions.php');
Connection();
function GetCoords(x)
{
echo 'Coords = '.$_GET['Coords'];
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With