|
|
|
รบกวนพี่ๆ ช่วยดู code เกี่ยวกับการแสดงผลช่วยหน่อยครับ การส่งแบบ get |
|
|
|
|
|
|
|
หน้าที่ generate qr ได้ตามนี้
Code (PHP) หน้า Gen QRCode
<?
session_start();
error_reporting(E_ALL & ~E_NOTICE);
include("connect.php");
include "QRPayment/phpqrcode/qrlib.php";
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
$actual_link = $actual_link."/yerpallpacific/?s="; // Part URL GET Check Key : https://xxxxx/yerpallpacific/?s=
function insertQr($dataType,$dataCode,$keyqr){
global $db ;
$query = "INSERT INTO `qrcode` (`id`,qrType,qrCode,`keyqr`) VALUES (null,'".$dataType."','".$dataCode."','".$keyqr."');";
$result = mysqli_query($db, $query);
}
function maxQr($dataType){
global $db ;
$query = "SELECT count(*) as countQr FROM `qrcode` WHERE qrType = '".$dataType."' ;";
$result = mysqli_query($db, $query);
$rs = mysqli_fetch_array($result);
return $rs[countQr];
}
function randQR($size,$type){
if($type=='N'){
$seed = str_split('abcdefghijklmnopqrstuvwxyz'.'0123456789'); // and any other characters
}else{
$seed = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
.'0123456789'); // and any other characters
}
shuffle($seed); // probably optional since array_is randomized; this may be redundant
$rand = '';
foreach (array_rand($seed, $size) as $k) $rand .= $seed[$k];
return $rand;
}
if($_POST[genQr] and $_POST[btnInput]){
$gen = $_POST[genQr] ;
for($i=0;$i<$gen;$i++){
if($_POST[qrtype]=="QR"){
$dataCode = "".randQR(12,"N");
$data = "MR".randQR(6,"T");
}
//echo $data;
insertQr($_POST[qrtype],$dataCode,$data);
$data = $data;
include("QRPayment/phpqrcode/QrRandom.php");
}
}
if($_POST[btnSave]){
if($_FILES["image"]["name"] != ""){
$imageName = "Picproduct/".$_POST[keyqr].".png";
if(move_uploaded_file($_FILES["image"]["tmp_name"],$imageName))
{
$imageNameUp = $imageName;
}
}
$query = "UPDATE `qrcode`
SET productname = '".$_POST[productname]."'
,productpic = '".$imageNameUp."'
WHERE id = '".$_POST[id]."'";
$result = mysqli_query($db, $query);
//echo $sql;
}
if($_POST[btnLogin]){
$query = "SELECT * FROM `sys_login_user` WHERE `user` LIKE '".$_POST[log_user]."' AND `login_pass` LIKE '".$_POST[log_pass]."'";
$result = mysqli_query($db, $query);
//echo $sql;
if($rs = mysqli_fetch_array($result)){
$_SESSION[em_login] = $rs[id];
//header("Location: index.php");
}else{
$alert = "Username หรือ Password ไม่ถูกต้อง";
//echo $alert;
}
}
if(!$_POST[qrtype]){
$_POST[qrtype] = "QR" ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>สร้าง Qr Code</title>
</head>
<body style="text-align: center;">
<h1 align="center">สร้าง Qr Code</h1>
<hr>
<?
if($_SESSION[em_login]){
?>
<a href="checkproduct.php" target="_blank"><h2>ตรวจสอบรายการ</h2></a>
<a href="logout.php" ><h2>ออกจากระบบ</h2></a>
<h2>สร้าง Qr Code</h2>
<form action="" method="post">
<h3>
URL : <? echo $actual_link; ?>
</h3>
<br>
ประเภท
<select name="qrtype">
<option <? if($_POST[qrtype]=="QR") echo "selected";?> value="QR">QR</option>
</select>
จำนวน <input type="number" name="genQr" /> <input type="submit" name="btnInput" value="สร้าง Qr Code" />
</form>
<hr>
<h2>รายการ Qr Code <span style="color: darkgreen;">ทั้งหมดจำนวน <?=maxQr($_POST[qrtype])?> รายการ</span></h2>
<form action="" method="post">
ประเภท
<select name="qrtype">
<option <? if($_POST[qrtype]=="QR") echo "selected";?> value="QR">QR</option>
</select>
รายการที่ <input type="number" name="minNumber" value="<?=$_POST[minNumber]?>" />
ถึงรายการที่ <input type="number" name="maxNumber" value="<?=$_POST[maxNumber]?>"/>
<input type="submit" name="btnSearch" value="แสดงรายการ" />
</form>
<?
if($_POST[genQr]){
$min = maxQr($_POST[qrtype])-$_POST[genQr]+1;
$max = maxQr($_POST[qrtype]);
}else if($_POST[minNumber] and $_POST[maxNumber]){
$min = $_POST[minNumber];
$max = $_POST[maxNumber];
}else{
$min = 1;
$max = 100;
}
?>
<h3>รายการที่ <?=$min?> ถึงรายการที่ <?=$max?> </h3>
<form action="QrPrint.php" method="post" target="_blank">
<input type="hidden" name="qrtype" value="<?=$_POST[qrtype]?>" />
<input type="hidden" name="minNumber" value="<?=$min?>" />
<input type="hidden" name="maxNumber" value="<?=$max?>"/>
<input type="submit" name="btnSearch" value="พิมพ์รายการ" />
</form>
<hr>
<?
$query = "SELECT * FROM `qrcode` WHERE qrType = '".$_POST[qrtype]."' ORDER BY id LIMIT ".($min-1).",".$max." ";
//echo $query;
$result = mysqli_query($db, $query);
while($rs= mysqli_fetch_array($result)){
?>
<div style=" width: 300px;height: 350px;border: 1px;border-style: dashed;position: relative;margin: 5px;float: left;" align="center" >
<form action="" method="post" enctype="multipart/form-data">
<span ><?=$rs[qrCode]?></span>
<br>
<img src="QRPayment/QRRANDOM/<?=$rs[keyqr]?>.png" height="100px" >
<br>
<span style="position: initial;left: 0px;"><?=$rs[keyqr]?></span>
<br>
<input type="hidden" name="minNumber" value="<?=$min?>" />
<input type="hidden" name="maxNumber" value="<?=$max?>"/>
<input type="hidden" name="id" value="<?=$rs[id]?>" />
<input type="hidden" name="keyqr" value="<?=$rs[keyqr]?>" />
</form>
</div>
<?
}
?>
<?
}else{
?>
<div align="center">
<div style="width:400px">
<form action="" method="post">
<h2>Username</h2>
<br><input type="text" name="log_user" style="font-size:20px" />
<h2>Password</h2>
<br><input type="password" name="log_pass" style="font-size:20px" />
<br>
<div style="color:#F00"><?=$alert?></div>
<br>
<input type="submit" name="btnLogin" style="font-size:20px" value="เข้าสู่ระบบ" />
</form>
</div>
</div>
<?
}
?>
</body>
</html>
เมื่อ Scan Qrcode จะได้ url เป็น : https://xxxx/yerpallpacific/?s=jhkcwndufx83
รูปผลลัพธ์เมื่อสแกน
ฟอร์เดอร์ yerpallpacific หน้า file index.php
<?
date_default_timezone_set("Asia/Bangkok");
session_start();
error_reporting(E_ALL & ~E_NOTICE);
include("../connect.php");
if( !function_exists('mobile_user_agent_switch') ){
function mobile_user_agent_switch(){
$device = '';
if( stristr($_SERVER['HTTP_USER_AGENT'],'ipad') ) {
$device = "ipad";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone') ) {
$device = "iphone";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'blackberry') ) {
$device = "blackberry";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) {
$device = "Mobile";
}
if( $device ) {
return $device;
} return false; {
return false;
}
}
}
if($_POST[qrCode]){
$checker_date = date("Y-m-d H:i:s");
$query = "UPDATE `qrcode`
SET status = status + 1
WHERE qrCode = '".$_POST[qrCode]."'";
$result = mysqli_query($db, $query);
$query = "INSERT INTO `checker` (`checker_id`, `key_qr`, `customer`, `mobile`, `checker_date`, checker_device)
VALUES (NULL, '".$_POST[qrCode]."', '".$_POST[QRName]."', '".$_POST[QRMobile]."', '".$checker_date."','".mobile_user_agent_switch()."');";
$result = mysqli_query($db, $query);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title></title>
<link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
<link href="../css/sb-admin-2.min.css" rel="stylesheet">
</head>
<body id="page-top">
<div id="wrapper">
<div id="content-wrapper" class="d-flex flex-column">
<div class="main">
<div class="scd_main">
<?
$query = "SELECT * FROM `qrcode` WHERE qrCode = '".$_GET['s']."' ";
$result = mysqli_query($db, $query);
while($rs=mysqli_fetch_array($result)){
?>
<div id="content">
<table class="col-12" style="height: 200px;">
<thead>
<tr style="height: 18px;">
<td style="background-color: #f06625; width: 676px; height: 18px;" colspan="3"> </td>
</tr>
</thead>
</table>
<!-- Begin Page Content -->
<div class="container-fluid">
<?
if($_POST[qrCode] and $rs[status]<=2){
?>
<table class="col-12" style="height: 400px;">
<tbody>
<tr style="height: 41px;">
<td style="background-color: #ffffff; width: 676px; height: 41px;" colspan="3"><img style="display: block; margin-left: auto; margin-right: auto;" src="../img/yerpall.webp" alt="" width="120" height="41" /></td>
</tr>
<tr style="height: 178px;">
<td style="background-color: #61a54f; width: 676px; height: 168px;" colspan="3"><img style="display: block; margin-left: auto; margin-right: auto;" src="../img/Success.webp" alt="" width="182" height="188" /></td>
</tr>
<tr style="background-color: #61a54f; height: 36px;">
<td style="width: 220px; height: 10px; text-align: center;">
<div>
<div class="text-white-50">Serial Number</div>
</div>
</td>
<td style="background-color: #61a54f; width: 220px; height: 10px; text-align: center;">
<div>
<div class="text-white-50">Last Checked</div>
</div>
</td>
<td style="width: 220px; height: 10px; text-align: center;">
<div>
<div class="text-white-50">Total Check</div>
</div>
</td>
</tr>
<tr style="height: 18px;">
<td style="background-color: #61a54f; width: 220px; height: 18px; text-align: center;"><storng class="text-white"><?=$rs[keyqr]?></storng></td>
<td style="background-color: #61a54f; width: 222px; height: 18px; text-align: center;"><storng class="text-white"><?=date("Y-m-d H:i:s")?></storng></td>
<td style="background-color: #61a54f; width: 222px; height: 18px; text-align: center;"><storng class="text-white"><?=$rs[status]?></storng></td>
</tr>
<tr style="height: 18px;">
<td style="width: 220px; height: 18px; text-align: center;"><a href="#" target="_blank"><img src="../img/Line.webp" alt="" width="66" height="56" /></a></td>
<td style="width: 222px; height: 18px; text-align: center;"><a href="#" target="_blank" rel="noopener"><img src="../img/Inbox.webp" alt="" width="66" height="56" /></a></td>
<td style="width: 222px; height: 18px; text-align: center;"><a href="#" target="_blank" rel="noopener"><img src="../img/Facebook.webp" alt="" width="66" height="56" /></a></td>
</tr>
</tbody>
</table>
</div>
<?
}else if($_POST[qrCode] and $rs[status]==3){
?>
<table class="editorDemoTable" style="height: 295px;">
<tbody>
<tr style="height: 178px;">
<td style="background-color: #d63733; width: 676px; height: 168px;" colspan="3"><img style="display: block; margin-left: auto; margin-right: auto;" src="../img/danger.webp" alt="" width="182" height="188" /></td>
</tr>
<tr style="background-color: #d63733; height: 36px;">
<?
$query_check = "SELECT * FROM `checker` WHERE key_qr = '".$rs[qrCode]."' ORDER BY checker_id";
$result_check = mysqli_query($db, $query_check);
while($rs_check=mysqli_fetch_array($result_check)){
$i++;
?>
<td style="width: 220px; height: 10px; text-align: center;" colspan="3"><strong>เวลาสแกนครั้งล่าสุด</strong><br />
<?=$i?> : <?=$rs_check[checker_date]?><br>
<strong>สแกนไปแล้ว <?=$rs[status]?> ครั้ง</strong>
<?
}
?>
</tr>
<tr style="height: 18px;">
<td style="background-color: #d63733; width: 220px; height: 18px; text-align: center;"> </td>
<td style="background-color: #d63733; width: 222px; height: 18px; text-align: center;">
<a href="#" class="btn btn-light btn-icon-split">
<span class="icon text-gray-600">
<i class="fas fa-arrow-right"></i>
</span>
<span class="text">Report Now</span>
</a>
</td>
<td style="background-color: #d63733; width: 222px; height: 18px; text-align: center;"> </td>
</tr>
</tbody>
</table>
<?
}else if($_POST[qrCode] and $rs[status]>4){
?>
<div class="col-12">
<div class="card bg-white text-white shadow mb-4">
<div class="text-center">
<img class="img-fluid px-3 px-sm-4 mt-3 mb-4"
src="../img/OOPS.webp" alt="...">
</div>
</div>
</div>
<?
}else{
?>
<?
if($_POST[qrCode]){
?>
<p></p>
<?
}
?>
<div class="scd-system">
<form method="post" id="CheckQRCode" name="CheckQRCode" action="" enctype="multipart/form-data">
<input type="hidden" value="<?=$rs[qrCode]?>" name="s" readonly="">
<input type="hidden" value="" readonly="">
<input type="hidden" value="" readonly="">
<input type="hidden" value="<?=$rs[qrCode]?>" name="qrCode">
<input type="hidden" value="CheckQR" name="action2">
<br><input type="hidden" name="chk" value="กดปุ่มเพื่อตรวจสอบ" onclick="this.disabled=true;this.value='Loading…';this.form.submit();">
</form>
<?
}
?>
<?
}
?>
</div>
</div>
</div>
<script>
window.onload = function(){
document.forms['CheckQRCode'].submit();
}
</script>
</div>
</div>
</body>
</html>
***** จุดประสงค์หลักที่ผมต้องการคือ อยากให้หน้า index.php เป็นหน้า info.php ที่อยู่ข้างนอก ฟอร์เดอร์ yerpallpacific
จากที่ตอนแรกที่ Gen และ Scan จะได้แบบนี้ : https://xxxx/yerpallpacific/?s=jhkcwndufx83 พอสแกนบันทึกเสร็จ อยากให้เป็น
https://xxxx/info.php
เนื่องจากตอนนี้พอผมสแกนเสร้จ มันก็จะอยู่หน้า https://xxxx/yerpallpacific/?s=jhkcwndufx83 อยู่เลยครับ (อยากให้เป็นแบบนี้ https://xxxx/info.php)
#### ขอบคุณครับ
Tag : PHP, MySQL, Laravel Framework
|
|
|
|
|
|
Date :
2021-11-03 12:07:43 |
By :
iOpen |
View :
484 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เพิ่มคำสั่ง redirect หลังจาก submit form บรรทัดที่ 37 ครับ
|
|
|
|
|
Date :
2021-11-03 14:14:28 |
By :
ผ่านมาเดา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|