我正在通过curl在PHP中提交一个表单但是反复出现 . 我在下面解释我的代码 .
testb.php:
<?php
$url ="http://example.com/restAPI/testb1.php?uid=7000942";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec ($ch);
echo $response;
curl_close ($ch);
?>
在这里,我调用一个文件 testb1.php
,其中存在我的表单 .
testb1.php:
<?php
require_once('../dev01/include/dbconfig.php');
require_once('../dev01/include/functions.php');
if(isset($_REQUEST['img']) && $_REQUEST['img']=="1"){
echo '<img src="../dev01/uploads/print/'.$_SESSION['cbdgimg'].'" alt="" />';
unset($_SESSION['cbdgimg']);
exit;
}
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
$conn = $db->connect();
$dbmap=array('first_name'=>'FirstName','last_name'=>'LastName','employeeid'=>'EmployeeId','site'=>'Site','position'=>'PositionType','id'=>'BadgeNumber','company'=>'Company','photo'=>'EmployeePhoto');
$dbo=new DBO();
$id=$dbo->prepare_param($_REQUEST['uid']);
//echo $id;exit;
// get badge from fsmasterbadge table
$badge = mysqli_query($conn,"SELECT * from fsmasterbadge where BadgeNumber='$id' AND EmployeeStatus <> '-1'") or die(mysqli_error());
if (mysqli_num_rows($badge) > 0){
$badge = mysqli_fetch_array($badge);
}else{
echo 'Badge not found.';return false;
}
if(!empty($badge)){
$tid=$badge['TemplateId'];
if($tid<1){
$tid=rand(1,3);
}
$template = mysqli_query($conn,"SELECT * from east_templates where id='".$tid."'") or die(mysql_error());
if (mysqli_num_rows($template) > 0){
$template = mysqli_fetch_array($template);
}else{
echo 'Template not found.';return false;
}
$factor=1.9;
$divheit=floor((85.7)* $factor);
$divwith=floor((53.9)* $factor);
$html='';
$html.='<div id="badge" style="padding:0;width:'.$divwith.'mm;height:'.$divheit.'mm;position:relative;" >';
$r=$template;
$txflds=unserialize($r['txtfields']);
$imflds=unserialize($r['imgfields']);//print_r($imflds);exit;
$bkflds=unserialize($r['bckfields']);
if(!empty($imflds) && empty($badge['EmployeePhoto'])){ // When Employee photo not uploaded.
echo '<script>alert("Please upload photo to print.");window.location = "create_updateimg.php?uid='.$id.'";</script>';
}else{
//update printCount
if(count($users)==1){
$PrintCount = (!empty($badge['PrintCount']) && $badge['PrintCount'] > 0)?$badge['PrintCount']+1:1;
$PrintDateTime = date("Y-m-d h:i:s"); //echo $PrintDateTime;exit;
$PrintBy = $_SESSION['UserName'];
$table = 'fsmasterbadge';
$columns = array("PrintCount","PrintDateTime","PrintBy");
$values = array($PrintCount,$PrintDateTime,$PrintBy);
$condition = "BadgeNumber = '".$id."'";
$reUpdate = $dbo->db_update($table, $columns, $values, $condition);
//echo $reUpdate ;exit;
}
}
$ctr=2;
foreach($bkflds as $v){
if($v['background'] !="#xyz"){
$v['x1']=floor($v['x1']*$factor);$v['x2']=floor($v['x2']*$factor);$v['y1']=floor($v['y1']*$factor);$v['y2']=floor($v['y2']*$factor);
$html.='<div style="background-color:'.$v['background'].';position:absolute;top:'.$v['y1'].'px;left:'.$v['x1'].'px;height:'.$v['y2'].'px;width:'.$v['x2'].'px;"></div>';
$ctr++;
}
}
foreach($txflds as $v){
if($v['name']=="")continue;
$fld=$dbmap[$v['name']];
//Get Company Name
$coid = $badge['Company'];
if(is_numeric($coid)){
// get badge from fsmasterbadge table
$cores = mysqli_query($conn,"SELECT company_name FROM east_companies where id='$coid'") or die(mysqli_error());
if (mysqli_num_rows($cores) > 0){
$cores = mysqli_fetch_array($cores);
}else{
echo 'Badge not found.';return false;
}
$badge[$fld] = ($v['name']=='company')?$cores['company_name']:$badge[$fld];
}
//Get Site Name
$siteid = $badge['Site'];
if(is_numeric($siteid)){
$sires = mysqli_query($conn,"SELECT site_name, display_name FROM east_site where id='$siteid'") or die(mysqli_error());
if (mysqli_num_rows($sires) > 0){
$sires = mysqli_fetch_array($sires);
}else{
echo 'Badge not found.';return false;
}
$badge[$fld] = ($v['name']=='site')?$sires['display_name']:$badge[$fld];
}
//end customize code for Comapny
$v['x1']=floor($v['x1']*$factor);$v['x2']=floor($v['x2']*$factor);$v['y1']=floor($v['y1']*$factor);$v['y2']=floor($v['y2']*$factor);
$width=$v['x2']-2; $height=$v['y2']-2;
$color=$v['color'];$font=$v['font'];$size=floor($v['size']*1.2);
$style="text-align:center;color:".$color.";position:absolute;top:".$v['y1']."px;left:".$v['x1']."px;width:".$width."px;height:".$height."px;font-size:".$size."px;font-family:".$font.";z-index:".$ctr;
if($v['name'] !="id"){
$html.='<div style="'.$style.'">'.stripslashes($badge[$fld]).'</div>';
}else{
while(strlen($badge[$fld])<7){
$badge[$fld]="0".$badge[$fld];
}
$size=floor($v['size']*1.5);if($size<48){$size=48;}
$style1="font-size:".$size."px;font-family:Code39AzaleaFont";
$html.='<div style="'.$style.'"><div style="margin-bottom:0px;'.$style1.'">*'.$badge[$fld].'*</div><div style="font-family:sans-serif, arial, verdana;font-size:12px;margin-top:0px;">*'.$badge[$fld].'*</div></div>';
}
$ctr++;
}
foreach($imflds as $v){
if($v['name']=="")continue;
$v['x1']=floor($v['x1']*$factor);$v['x2']=floor($v['x2']*$factor);$v['y1']=floor($v['y1']*$factor);$v['y2']=floor($v['y2']*$factor);
$fld=$dbmap[$v['name']];
$width=$v['x2']-2; $height=$v['y2']-2;
$style="position:absolute; top:".$v['y1']."px;left:".$v['x1']."px;width:".$width."px;height:".$height."px;z-index:".$ctr;
$html.='<div style="'.$style.'"><img src="../dev01/uploads/photo/'.$badge[$fld].'" alt="photo" style="width:100%;height:100%;" /></div>';
}
if($r['image'] !=""){
$v=unserialize($r['logoflds']);
$v['x1']=floor($v['x1']*$factor);$v['x2']=floor($v['x2']*$factor);$v['y1']=floor($v['y1']*$factor);$v['y2']=floor($v['y2']*$factor);
$html.='<div id="divlogo" class="drgble ui-widget-content" style="position:absolute;top:'.$v['y1'].'px;left:'.$v['x1'].'px;height:'.$v['y2'].'px;width:'.$v['x2'].'px;z-index:'.$ctr.'"><img src="../dev01/uploads/logo/'. $result[0]['image'].'" style="width:100%;height:100%;" alt ="logo" /></div>';
}
$html.='</div>';
}
if(isset($_REQUEST['actn'])){
echo '1';exit;
}
//$html.='<p>The meta elements of this document describe the document and its keywords.</p>';
?>
<html class="no-js css-menubar" lang="en">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<meta name="description" content="Blue Summit">
<meta name="author" content="">
<title>Visitor badge</title>
<link rel="apple-touch-icon" href="../dev01/images/apple-touch-icon.png">
<!--link rel="shortcut icon" href="images/favicon.png"-->
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" >
<link rel="stylesheet" href="../dev01/css/site.min.css">
<script src="../dev01/js/jquery.min.js"></script>
<script src="../dev01/js/jquery-ui.min.js"></script>
<script src="../dev01/js/html2canvas.js"></script>
<style>@font-face{font-family: Code39AzaleaFont;src: url("../dev01/fonts/code39/Code39Azalea.eot") format("embedded-opentype"), url("./fonts/code39/Code39Azalea.woff") format("woff"), url("../dev01/fonts/code39/Code39Azalea.ttf") format("truetype"), url("../dev01/fonts/code39/Code39Azalea.svg#Code39Azalea") format("svg"); font-weight: normal;font-style: normal;}</style>
</head>
<body>
<?php echo $html;?>
<div style="margin-top:10px;" id="imgdiv"></div>
<form method="post" id="printimg">
<input type="hidden" name="actn" value="1"><input type="hidden" name="idta" id="idta" value="">
</form>
<script type="text/javascript">
var id=<?php echo $_REQUEST['uid']; ?>;
//console.log('badge id',id);
$('#printimg').submit();
</script>
</body>
</html>
这里当我写 $('#printimg').submit()
提交表单时,页面加载反复发生意味着页面正在连续执行 . 在这里,我需要提交表单并执行一次 . 请帮我解决这个问题 .