In this article, btcschool applies google QR service for rapid display. In production, it is advise to have local generator library for better performance.
<?php
include_once "../libraries/vendor/autoload.php";
include_once("html_iframe_header.php");
$supportChains = ['bitcoin'=>"Bitcoin", 'bitcoincash'=>"Bitcoin Cash", 'ethereum'=>"Ethereum"];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
$ch1 = urlencode("{$_POST['chain']}:{$_POST['recipient']}?amount={$_POST['amount']}&message={$_POST['message']}");
?>
<div class="alert alert-success">
<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=<?php echo $ch1?>&choe=UTF-8"/>
</div>
<?php
} catch (Exception $e) {
$errmsg .= "Problem found. " . $e->getMessage();
}
}
if ($errmsg) {
?>
<div class="alert alert-danger">
<strong>Error!</strong> <?php echo $errmsg?>
</div>
<?php
}
?>
<form action='' method='post'>
<div class="form-group">
<label for="chain">Chain:</label>
<?php
foreach($supportChains as $k=>$v) {
?>
<div class="form-check-inline">
<label class="form-check-label">
<?php
echo "<input type='radio' class='form-check-input' name='chain' value='{$k}'".($k == $_POST['chain'] ? " checked": "")."/>{$v}";
?>
</label>
</div>
<?php
}
?>
</div>
<div class="form-group">
<label for="recipient">Recipient Address:</label>
<input class="form-control" type='text' name='recipient' id='recipient' value='<?php echo $_POST['recipient']?>'>
</div>
<div class="form-group">
<label for="amount">Amount:</label>
<input class="form-control" type='text' name='amount' id='amount' value='<?php echo $_POST['amount']?>'>
</div>
<div class="form-group">
<label for="message">Message:</label>
<input class="form-control" type='text' name='message' id='message' value='<?php echo $_POST['message']?>'>
</div>
<input type='submit' class="btn btn-success btn-block"/>
</form>
<?php
include_once("html_iframe_footer.php");
In case app scanner doesn't work to meet your expectation, such as ethereum's ERC20 token, you may consider to input recipient address only.
<?php
include_once "../libraries/vendor/autoload.php";
include_once("html_iframe_header.php");
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
$ch1 = urlencode($_POST['recipient']);
?>
<div class="alert alert-success">
<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=<?php echo $ch1?>&choe=UTF-8"/>
</div>
<?php
} catch (Exception $e) {
$errmsg .= "Problem found. " . $e->getMessage();
}
}
if ($errmsg) {
?>
<div class="alert alert-danger">
<strong>Error!</strong> <?php echo $errmsg?>
</div>
<?php
}
?>
<form action='' method='post'>
<div class="form-group">
<label for="recipient">Recipient Address:</label>
<input class="form-control" type='text' name='recipient' id='recipient' value='<?php echo $_POST['recipient']?>'>
</div>
<input type='submit' class="btn btn-success btn-block"/>
</form>
<?php
include_once("html_iframe_footer.php");