0

我对 firefox 和 chrome 有一个大问题,我的编码在 IE 和 sfari 上完美运行。在 firfox 和 chrome 中不起作用的事情是我有一个二维会话数组调用“bill_array”。在这两个浏览器中没有完美地清除它。当我按下 x 按钮时。但其他两个做得很好。

<?php
//checking for perfect loging
session_start();
require ("connection.php");
if (!isset($_COOKIE['username']) && !isset($_COOKIE['password'])) {
    header('location:home.php');
    exit();
}
else {
    $user_name = $_COOKIE['username'];
    $user_pass = $_COOKIE['password'];
}
/////////////////////////////////////
?>
<?php
//#####################################################################################################//
//CANCELING THE BILl//      
//#####################################################################################################//
?>
<script type="text/javascript">
function textsizer(e) {
    var evtobj=window.event? event : e;
    var element = evtobj.target ? evtobj.target : evtobj.srcElement;
    if (element.tagName.toLowerCase() == "body") {
        var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode;
        var actualkey=String.fromCharCode(unicode)
        if(actualkey=="x"){
            location.href="clearsession.php";
            }

            }
        }

document.onkeypress=textsizer
</script>

<?php 
        //collecting posted variables by pressing addanother button
        if(isset($_POST['adnother'])) {
        $date = $_POST['date'];
        $billnmbr = $_POST['billnmbr'];
        $optionlist=$_POST['optionlist'];
        $itemcode = $_POST['itemcode'];
        $itemname = $_POST['itemname'];
        $exdate = $_POST['exdate']; 
        $eachprice = $_POST['eachprice'];   
        $itmtotal = $_POST['itmtotal'];
        $qty = $_POST['qty'];
        $wasFound=false;
        $i=0;   
// check for >>>>>>>>>>> if the session bill_array  array  is not set or cart array is empty <<<<<<<<<<<<<<<
    if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
        // Run if the bill_array is empty or not set
        $_SESSION["bill_array"]= array(1 => array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "qty"=> $qty, "itmtotal"=> $itmtotal));
    } else {
        // Run if the bill has at least one item in it
        foreach($_SESSION["bill_array"] as $each_item) {
            $i++;
            while(list($key,$value)=each($each_item)){
                if($key=="itemcode" && $value == $itemcode){
                    // That item is in cart already so push a error message in to screen
                    $wasFound = true; ?>
                    <script type="text/javascript">
                    var error = "<?= $wasFound ?>";
                    if(error == "1") {
                    alert("You trying to add same item twice")
                    }
                    </script>
                    <?php 
                    }//close if condition
            }//close while loop
        }//close foreach loop
//if the next item is not in the bill and then add it to the bill_array     
    if($wasFound==false){
    array_push($_SESSION["bill_array"],array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "qty"=>$qty, "itmtotal"=> $itmtotal));
}//clos if condition
    }//close else statment
        }//close ifisset
        ?>
<!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>Front-end Billing</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<link href="main.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
.mainheder {
    font-size: 36px;
    font-weight: bolder;
    color: #00C;
    text-align: center;
}
#headertopic {
    position:absolute;
    left:304px;
    top:1px;
    width:395px;
    height:44px;
    z-index:1;
    background-color: #999900;
}
#mainmenue {
    position:absolute;
    left:208px;
    top:78px;
    width:614px;
    height:696px;
    z-index:1;
}
#dateandtime {
    position:absolute;
    left:790px;
    top:251px;
    width:208px;
    height:82px;
    z-index:1;
}
#redcross {
    position:absolute;
    left:377px;
    top:321px;
    width:247px;
    height:239px;
    z-index:0;
}
#usrlogin {
    position:absolute;
    left:4px;
    top:216px;
    width:265px;
    height:184px;
    z-index:1;
}
#address {
    position:absolute;
    left:2px;
    top:462px;
    width:204px;
    height:155px;
    z-index:2;
}

#logdas {
    position:absolute;
    left:10px;
    top:92px;
    width:197px;
    height:58px;
    z-index:1;
}
.logdas {
    font-weight: bold;
    color: #00F;
}
#pagetheam {
    position:absolute;
    left:330px;
    top:186px;
    width:341px;
    height:24px;
    text-align: center;
    font-size: 18px;
    font-weight: bolder;
    color: #0CF;
    text-decoration: underline;
}
#billingitems {
    position:absolute;
    left:21px;
    top:266px;
    width:731px;
    height:240px;
    z-index:10000;
    border-style:groove;
    border-width:thick;
}
#printlayout {
    position:absolute;
    left:768px;
    top:267px;
    width:211px;
    height:279px;
    z-index:100000;
    text-align: center;
    overflow: auto;
    border-style:solid;
    border-width:thin;
}
.printlayoutshopname {
    font-size: 14px;
    font-weight: bold;
    color: #000;
}
.billaddrs {
    font-size: 10px;
}
.bilnmbr {
    font-size: 10px;
    text-align: left;
}
.amount {
    font-size: 12px;
    font-weight: bold;
}
.itemcode {
    font-size: 14px;
    font-weight: bold;
}
.expiredate {
    font-size: 14px;
    font-weight: bolder;
    color: #F00;
    text-decoration: blink;
}
#copyright2 {
    position:absolute;
    left:757px;
    top:565px;
    width:223px;
    height:87px;
    z-index:1;
}
.copyright2 {
    font-size: 12px;
    font-weight: bold;
}
#packsize {
    position:absolute;
    left:321px;
    top:7px;
    width:173px;
    height:24px;
    z-index:1;
}
</style></head>
<? // this java script used to submit item code on -> arrow key press unicode value of that button is 39 ?>
<script type="text/javascript">
function submitthis(e){
var unicode=e.keyCode? e.keyCode : e.charCode
if (unicode ==39)   {
    var value1 = document.form1.itemcode.value;
    location.href="biling.php?itmcde="+value1;
    //alert(unicode)
    var optionvalue1 = form1.optionlist.selectedIndex;
    var optionvalue2 = form1.optionlist.options[optionvalue1].text
    if( optionvalue2 == "set size"){ alert ("select a size"); }
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this java script used to submit item name on -> arrow key press unicode value of that button is 39
function submitname(e){
var unicode=e.keyCode? e.keyCode : e.charCode
if (unicode ==39)   {
    var value1 = document.form1.itemname.value;
    location.href="biling.php?itmnam="+value1;
    //alert(unicode)
}
}
</script>
<? ///////////////////////////*********************************//////////////////////////////////////////////// ?>
<?php 
//when item code typed and pressed the -> arrow key, the itemcode field is submited to this form using get method
//below code grab that submited value, and retrive information on that itemcode 
if(isset($_GET['itmcde'])) {
    $itmcde =$_GET['itmcde'];
    $query = "SELECT *
                FROM `stock`
                WHERE Item_code = '{$itmcde}' 
                ";
$rs_result = mysql_query ($query); 
//if the item code is not in our database below if condition will give an error message and it will redirect the user to billing.php
if (mysql_num_rows($rs_result)==0){ ?>
                    <script type="text/javascript">
                    alert("This item code is not in oure data base")
                    location.href="biling.php";
                    </script>
                    <?php exit(); }
else {
while ($row = mysql_fetch_assoc($rs_result)) { 
$itemname=$row["Item_name"];
$expdate=$row["expier_date"];
}

//if the items expire date is passed or if it has only 3,2 or 1 day to expier belove code push a error message.
$ex_expdate = preg_replace('\'-\'', '', $expdate);
$today=Date("Ymd");
$moredate=$ex_expdate-Date("Ymd");
if($ex_expdate <= $today){ ?>
                    <script type="text/javascript">
                    alert("Item has Expired")
                    </script>
                    <?php ;}
if($moredate==3){ ?>
                    <script type="text/javascript">
                    alert("3 more days to expire")
                    </script>
                    <?php ;}
if($moredate==2){ ?>
                    <script type="text/javascript">
                    alert("2 more days to expire")
                    </script>
                    <?php ;}
if($moredate==1){ ?>
                    <script type="text/javascript">
                    alert("1 more days to expire")
                    </script>
                    <?php ;}
}
}
//////////////////////////////^^^^^^^^^^^^^^^^^^^^//////////////////////////////
//when item name typed and pressed the -> arrow key, the itemname field is submited to this form using get method
//below code grab that submited value, and retrive information on that itemname 
if(isset($_GET['itmnam'])) {
    $itmnam =$_GET['itmnam'];
    $query = "SELECT *
                FROM `stock`
                WHERE Item_name = '{$itmnam}' 
                ";
$rs_result = mysql_query ($query); 
//if the item code is not in our database below if condition will give an error message and it will redirect the user to billing.php
if (mysql_num_rows($rs_result)==0){ ?>
                    <script type="text/javascript">
                    alert("This item name is not in oure data base")
                    location.href="biling.php";
                    </script>
                    <?php exit(); }
else {
while ($row = mysql_fetch_assoc($rs_result)) { 
$itemcodename=$row["Item_code"];
$expdatename=$row["expier_date"];
}

//if the items expire date is passed or if it has only 3,2 or 1 day to expier belove code push a error message.
$ex_expdate = preg_replace('\'-\'', '', $expdatename);
$today=Date("Ymd");
$moredate=$ex_expdate-Date("Ymd");
if($ex_expdate <= $today){ ?>
                    <script type="text/javascript">
                    alert("Item has Expired")
                    </script>
                    <?php ;}
if($moredate==3){ ?>
                    <script type="text/javascript">
                    alert("3 more days to expire")
                    </script>
                    <?php ;}
if($moredate==2){ ?>
                    <script type="text/javascript">
                    alert("2 more days to expire")
                    </script>
                    <?php ;}
if($moredate==1){ ?>
                    <script type="text/javascript">
                    alert("1 more days to expire")
                    </script>
                    <?php ;}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
?>
<script type="text/javascript">
var expdate = "<?= $expdate ?>";
</script>
<body>
<div id="wrap">
<div id="headertopic" class="mainheder">Accoutnig for Phamacy</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="mainmenue"> <?php  
                        //including the menu
                        include 'index.html' ;?> </div>
<?php
      //select a bill number form the database and increment it.    
      $data = mysql_query("SELECT * FROM billnumber ") ;
      $info = mysql_fetch_array( $data ); 
      $oldnumber = $info['bill_number'];
      $oldnumber= $oldnumber + 1;
      $Transaction_number = "PM". $oldnumber ;
      ?>
<div id="logdas">
 <p class="logdas">Logged in as :  <?php echo $user_name; ?></p>
 <p class="logdas"> Date : <?php echo date("Y-m-d") ?> </p>
 <p class="logdas"> Bill Number : <?php  echo $Transaction_number; ?></p>
</div>
<div id="pagetheam">Front-end Billing </div>
<div id="billingitems">
<form id="form1" name="form1" method="post" action="biling.php">
<input type="hidden" name="date" id="date" value=" <?php echo date("Y-m-d") ?> " />
<input type="hidden" name="billnmbr" id="billnmbr" value="<?php  echo $Transaction_number; ?>" />
<table width="731" height="224" border="1"  style="border:thin; border-color:#FFF;" >
<tr>
<td height="26" class="itemcode">Tablet/pack/ size </td>
<td><select name="optionlist"  onchange="handleselect(this.form)" id="optionlist">
     <option>set size</option>
     <option>pac.</option>
     <option>each.</option>
     <option>mg</option>
     <option>g</option>
     <option>ml</option>
     </select>
</td>
<td align="right" class="itemcode">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="120" height="26" class="itemcode">Item Code</td>
<td width="144"><input type="text" name="itemcode" id="itemcode" tabindex="1"   value="<?php if(isset($_GET['itmcde'])) {echo $itmcde; }if(isset($_GET['itmnam'])) {echo $itemcodename; }?>" onKeyUp="submitthis(event)" /></td>
<td width="215" align="left" class="itemcode">&nbsp;</td>
<td width="222"><div id="packsize"></div>
<script>
//creating a text box when select mg/g/ml/l frm the drp dwn   
function handleselect(form1){
    var selIndex = form1.optionlist.selectedIndex;
    var selName = form1.optionlist.options[selIndex].text
    if(selName == "mg" || selName == "g") {
    //var yesitis = '<input type="text" name="size" id="size" />'   }
    //alert (yesitis);
    //document.getElementById('apDiv2').write(yesitis);
    var txt=document.getElementById("packsize");
    txt.innerHTML='<input type="text" name="size" id="size" />';
}
    }
</script>
</td>
</tr>
<tr>
<td height="26" class="itemcode">Item Name</td>
<td><input type="text" name="itemname" id="itemname" tabindex="2"  value="<?php if(isset($_GET['itmcde'])) { echo $itemname  ;}if(isset($_GET['itmnam'])) { echo $itmnam  ;}   ?>"onKeyUp="submitname(event)" /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="26" class="itemcode">Expier Date</td>
<td><input type="text" name="exdate" id="exdate"  value="<?php if(isset($_GET['itmcde'])) { echo $expdate;}if(isset($_GET['itmnam'])) { echo $expdatename ;}?>"  /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="23" class="itemcode">Item Price</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="26" colspan="2"><span class="itemcode">Each :&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="eachprice" id="eachprice" /></td>
<td><span class="itemcode">Qty :</span><input type="text" name="qty" id="qty" tabindex="3" /></td>
<td><span class="itemcode">Total :</span><input type="text" name="itmtotal" id="itmtotal" /></td>
</tr>
<tr>
<td height="23" colspan="4">&nbsp;</td>
</tr>
<tr>
<td height="28"><input name="Submit" type="submit" id="Submit" value="Print" /></td>
<td height="28"><input type="submit" name="adnother" id="adnother" value="add another item" tabindex="4" /></form></td>
<td><input type="button"  name="rmvitm" id="rmvitm" value="Remove Itm" /></td>
<td>
<form id="form2" name="form2" method="post" action="biling.php">
<input type="submit"  name="cancelbill" id="cancelbill" value="Cancell Bill" />
</form></td>
</tr>
</table>

</div>
<div id="printlayout">
<table width="211" border="0">
<tr>
<td colspan="4" align="center" class="printlayoutshopname"> Yasitha Pharacy <br /> </span>
<span class="billaddrs">22,Colombathanthiri Mawatha, Ethulkotte, Kotte.</span></td>
</tr>
<tr>
<td colspan="2" class="bilnmbr">Bill NO:<?php  echo $Transaction_number; ?></td>
<td width="39" class="bilnmbr">&nbsp;</td>
<td width="67" class="bilnmbr">Date:<?php echo date("Y-m-d") ?></td>
</tr>
<tr>
<td width="42">&nbsp;</td>
<td width="45" class="bilnmbr">Each</td>
<td class="bilnmbr">Qty.</td>
<td class="bilnmbr">Total</td>
</tr>
<?php 
if(isset($_POST['adnother'])) {
//taking items in the bill to variables if the bill_array is not empty.
$cartOutput="";
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) { //if not yet any item added to the session array , do nothing. 
}
else {
//else if there is any item on session array take its value and print
$i = 0;
foreach ($_SESSION["bill_array"]as $each_item ): ?>
<tr>
<td colspan="4" height="2" class="bilnmbr"><?php echo $each_item['itemcode']."-".$each_item['itemname'] ; ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="bilnmbr"><?php echo $each_item['eachprice']; ?></td>
<td class="bilnmbr"><?php echo $each_item['qty']; ?></td>
<td class="bilnmbr"><?php echo $each_item['itmtotal']; ?></td>
</tr>
<?php endforeach; 
}
}
////////////////////////////////////////
?>   
</table>
<p class="bilnmbr">User ID:<?php echo $user_name; ?></p>
</div>

<div id="copyright2">
<p class="copyright2">Version- alpha release 0.0.1<br />
<sup> &copy; </sup> 2012 3Links ITS <sup>&reg;</sup>- All   Rights Reserved.<br />
3Links ITS <sup>&reg;</sup><br />
22,Colombathanthiri Mawatha,<br />
Ethulkotte Kotte    <br />
Tel : 011-2871106<br />
Mobile :0715716890  </p>
</div>
<?php //closing div for wrapper?></div> 

</body>
</html>

这是我的 clearsession.php 页面

<?php 
session_start();
session_unset();
session_destroy();
$_SESSION["bill_array"] = array();
header('location:biling.php') ;
?>
4

2 回答 2

2

我刚刚遇到了非常相似的问题,经过大量的头部撞击后,我找到了解决方案。我把它贴在这里,所以它可以帮助别人。我的问题;示例代码

//set my variable
$_SESSION['variable'] = array(1,2);
// unset my variable
unset($_SESSION['variable']);
// check variable isset
if ( isset($_SESSION['variable']) ) {
   echo "isset";
} else {
    echo "not set";
}

对于 IE、Chrome、Safari,所有浏览器都报告“未设置”,而 Firefox 报告“isset”。原来我的域上有 2 个 PHPSESSID cookie;例如

  • 域名.co.uk
  • www.domain.co.uk

我删除了非 www cookie(因为我使用的是 www),我立即得到了与其他浏览器相同的结果,并且符合预期。解决方案:确保只使用一个 PHPSESSID cookie。

我希望这对其他人有帮助。

于 2013-06-25T13:58:19.503 回答
-1

您应该取消设置单个变量以取消设置整个数组。

于 2012-07-18T06:16:18.963 回答