I'm trying to pass some data (JSON
) to another page by scanning a QR code.
The page where the data is send to, contains a HTML
form. I want to use that form as a last chance to correct the data before sending it to the database.
I found here at S.O. a way to pass the data using cURL: (https://stackoverflow.com/a/15643608/2131419)
QR code library: http://phpqrcode.sourceforge.net
I use the QR code execute this function:
function passData () {
$url = 'check.php';
$data = array('name' => 'John', 'surname' => 'Doe');
$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode($data);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_exec($ch);
curl_close($ch);
# Print response.
return $result;
}
Create QR code:
QRcode::png(passData(), $tempDir.'007_4.png', QR_ECLEVEL_L, 4);
echo '<img src="'.$tempDir.'007_4.png" />';
Check.php
<?php $data = json_decode(file_get_contents("php://input"), true); ?>
<form method="post" action="handle.php">
<input type="text" name="name" value="<?php echo $data['name'];?>" /><br />
<input type="text" name="surname" value="<?php echo $data['surname'];?>" /><br />
<input type="submit" />
</form>
Problem:
I can pass the data to check.php, but it's returning plain text instead of a useable HTML
form.
Hope someone can help!
EDIT
Some clarification:
What I actually want is, to scan the QR code, which executes the passData() function. Then the 'QR code scanner app', needs to open a browser, which shows check.php
with the form AND the passed data as the values
of the input
fields.
Now, I get only the response of check.php
(plain text).
When I pass an URL
instead of the passData()
function like:
QRcode::png("http://www.google.com", $tempDir.'007_4.png', QR_ECLEVEL_L, 4);
The app asks if I want to go to http://www.google.com.