You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, April 20th 2017, 11:02pm

Send Data out of krpano

Hi

I am working on a project where you can choose items and I wan't to send the list/data of those items to an other device to check/edit this data. There you would read this Data and Display it on a Website (html form?).

Now i could write the Data somehow to a Database or another way would be a PHP Post Request.
Problem there is that i understand krpano xml quite good, but not so much of PHP and/or Databases.

Has anyone already this something like this? Which way should i go?
How could I do a POST Request over a krpano onclick action?

Thanks for your fast answers
Sven

Timescale

Trainee

Posts: 120

Location: Netherlands

Occupation: Archaeologist, Timescale R&D

  • Send private message

2

Sunday, April 23rd 2017, 3:21pm

data to an from KRpano

This isn't as hard as you think, but you will have to make sure the exposed back-end is safe and sane in PHP. The interface could look something like this :


Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function dataHandler(Variable,Value,ID){
	
   var Data = new FormData();
   Data.append('ID', ID);
   Data.append('Value', Value);
Data.append('Variable', Variable);

   var DBIO = new XMLHttpRequest();
   DBIO.onreadystatechange = function() {
    		if (DBIO.readyState == 4) {
				parseData(DBIO.responseText);
    		}	
   DBIO.open('POST', './DBIO.php', true);
   DBIO.send(Data);
}


On the PHP side, you have a number of options, but it is important to make sure that it is secure because this interface is exposed to the world. There are plenty examples on how to do this properly, but essentially, you have to make sure that the PHP script isn't able to access and read/write in places where it shouldn't.

DBIO.php can be build to both read and write from a database. In case of a non-null value and no ID, you could make it insert, With an ID and a value, do an update and with a ID and a null value, do a select.

For returning data, you could simply return a string and parse it in JS. I tend to generate XML and return that for parsing, but that is a personal preference.


A basic setup would look something like this. You can find most code snippets you need easily online.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

$ID = $_POST['ID'];
$variable = $_POST['variable'];
$value = $_POST['value'];

/*
code to make sure the variable is valid to use (an array or something) and code to clean up the data for injection prevention..

*/

/* 
database connection code

*/

if (trim($ID) == "" ){
// build a insert query
$DBIOResult = 'INSERT';
} else if (trim($ID) != "" AND trim($value != "") ){
// build a update query
$DBIOResult = 'UPDATE';
} else if (trim($ID) != "" AND trim($value == "") ){
// build a select query
$DBIOResult = 'SELECT';
} 

/*
 code to execute query
*/

?>
<?xml version="1.0" encoding="UTF-8"?> 
 <DBIO>
   <DBIOResult><?php echo $DBIOResult?></DBIOResult>
   <ID><?php echo $ID?></ID>
   <variable><?php echo $key?></variable>
   <value><?php echo $value?></value>
 </DBIO>


You can make this as simple or complex as you like, but the important part is the security of the interface. I'd advice to follow these instruction for the DBIO : https://phpdelusions.net/pdo

This post has been edited 4 times, last edit by "Timescale" (Apr 23rd 2017, 3:54pm)


3

Monday, May 8th 2017, 3:24pm

Hi Timescale

Thanks for your post. I am trying to understand how this works.
Important for me is, that I don't need to go out the VR mode.

Our actual solution works with opening an URL that has all the information stored in it.
Then the PHP reads out the Data and sends an Email with all the Data to the Customers that then can work with it.

So can I make this request without leaving the KRpano VR mode?

Thanks
Sven

4

Tuesday, May 9th 2017, 5:11pm

hi

i just included jquery and then it's really simple!

Source code

1
$.ajax({ url: yoururl, async: false});



I had to set "async: false" as otherwise it's not working on chrome for android.


Sven