how to add a qr code image if the text code $result['data']['checkout_url'] is more than 100
Image src code
<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl=<?= $result['data']['checkout_url']; ?>" width="200">
Code to edit
if (filter_var($result['data']['checkout_url'], FILTER_VALIDATE_URL)) {
return redirect()->to($result['data']['checkout_url']);
} else {
$this->session->setFlashdata('success', 'Silahkan transfer sebesar Rp ' . number_format($data_post['quantity'],0,',','.') . ' ke ' . $result['data']['checkout_url'] . ' melalui ' . $data_method[0]['name'] . ' sebelum 1x24 jam.');
return redirect()->to(str_replace('index.php/', '', site_url(uri_string())));
}
} else {
$this->session->setFlashdata('error', $result['message']);
return redirect()->to(str_replace('index.php/', '', site_url(uri_string())));
}
}
CodePudding user response:
$chl = isset($_GET['chl']) ? $_GET['chl'] : ''; //Get the value of chl from the img
if(!empty($chl)) // If its not empty
{
$chl_length = strlen($chl); //Get the length of the string - example 35
if($chl_length > 100) { //If the str length is longer the 100 chars
//DO this
}
else {
//Do something else
}
else {
echo "Error: chl is empty";
}
The problem is you should not set raw url in chl
query params.
Prefer do this, use urlencode()
function
<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl=<?= urlencode($result['data']['checkout_url']); ?>" width="200">
After scanning the qr, use urldecode()
function to change it to raw url again before doing next process.