New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get data over HTTP with PHP on my server? #492
Comments
OK I haven't touched PHP in a long time but let me try to answer... In CustomURL settings - In your PHP page, something like
Of course from there you'll need to write it to your file or database, the So for file, for example, you could do
|
Yep, it's right but it doesn't work! GPSLogger for Android
test.php <?php
if (isset($_GET["lat"])) {
echo $_GET["lat"];
} else {
echo "ERROR";
}
?> http://.../test.php
|
Wait - are you hitting the page directly in your own browser? You won't see anything that way because there's no querystring variables being sent. To see it working in your own browser, go
GPSLogger will be sending lat/lon to that URL but you won't be able to see that because the values are being echoed back to the app, not to yourself. You'll have to write some code to take those lat/lon values and store them somewhere like a file or a DB. Then you can test end-to-end. |
Try writing from the PHP page to a file
Then hit the page from GPSLogger. Then look for a |
Oh it's works! I'm too confused. Why I can't get lat and lon directly in test.php, to save into PHP variables and then to print them? Thank you, @mendhak! |
Web pages are request-response. When you hit that page it looks at what querystring you sent, prints it to the page and responds with that page back to you. Similarly when GPSLogger adds its querystring, the response is sent back to GPSLogger. So you can definitely save lat/lon to PHP variables, just that you have to also send them in the querystring. In your example you were hitting test.php but not sending any lat/lon. If you hit
You should see it saved to variable then printed out to page |
So what is the best solution to get lat, lon, etc with your app, in PHP to store them in a MySQL database and to print them in a web page in your opinion? I need some advices about it, because maybe I'm doing it wrong. |
You'll need two parts to this. The first is a 'receiver.php' page which GPSLogger sends its data to every few minutes or whatever you've configured. In this page, write the values to a file or database. The second is a 'display.php' - when you browse to this page it goes and queries the database or file and displays those values on the page. If you're going to do a lot of logging, maybe consider a database instead of a file. Might be worth mentioning - export-mike has written an API which can look at GPX files uploaded to Dropbox. So you'd have to enable Dropbox upload and your display page would query the Dropbox API instead. |
Thank you @mendhak, now it works! I've created a PHP file that get latitude and longitude from your app over HTTP and insert them into my database online every n seconds. try {
$connnection = new PDO("mysql:host=XXX;dbname=XXX", "XXX", "XXX");
$connnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$latitude = $_GET["lat"];
$longitude = $_GET["lon"];
if ($latitude != null && $longitude != null) {
$sql = "INSERT INTO GPS (LATITUDE, LONGITUDE)
VALUES ('" . floatval($latitude) . "', '" . floatval($longitude) . "')";
$connnection->exec($sql);
}
} catch(PDOException $e) {
echo $e->getMessage();
} |
Hey that's great to know. Future searchers will benefit from this too, so thanks |
what is the full url string your using in the custom URL option? |
I need help, please! I'm very confused.
How I can print on my server at address .../.../test.php data as ?lat=%LAT&lon=%LON with custom URL modality over HTTP with PHP?
(I will offer you a coffee, your app is great!)
Thanks!
The text was updated successfully, but these errors were encountered: