how to correct php redirection error in server

i have error redirection in server for php shopping cart
what i have done so far is in jquery i have to send item id and unit price to shop-cart.php
my code in js is

var id = getUrlParameter('id');
var unitprice=$(".couponPrice").text(); 
window.location = 'shop-cart.php?id=' + id +'&unitprice='+ unitprice;

when click on add to cart button it redirect to

www.domainname/shopcart.php?id=sp_gt1&unitprice=1

and in shop cart i have to generate a order id and my shop-cart.php code is

<?php
ob_start();
session_start();
//error reporting
include "script/db.php";
error_reporting(E_ALL);
ini_set('display_errors','1');
error_reporting(E_ERROR | E_PARSE);
?>


<?php
////////order id generate/////////
date_default_timezone_set('Asia/Kolkata');
        $stamp = date("ymdhis");

$orderid = $stamp;


if(isset($_GET['OrderId']))
{
    $_SESSION['OrderId']=$_GET['OrderId'];
}


/////////////////////////////////////////////////////////////////////////////
// SECTION-1     (if you want to add items to your shopping cart)
/////////////////////////////////////////////////////////////////////////////
if (isset($_GET['id'])) 
{

    $pid = $_GET['id'];
    $quantity=1;
    $unitprice=$_GET['unitprice'];

    $wasFound = false;
    $i = 0;

    // If the cart session variable is not set or cart array is empty
    if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1)                  { 

        // RUN IF THE CART IS EMPTY OR NOT SET
        $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => $quantity,"unit_price"=>$unitprice));
    } 
    else 
    {
        // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
        foreach ($_SESSION["cart_array"] as $each_item) { 
              $i++;
              while (list($key, $value) = each($each_item)) {
                  if ($key == "item_id" && $value == $pid) {
                      // That item is in cart already so let's adjust its quantity using array_splice()
                      array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1,"unit_price"=>$unitprice)));
                      $wasFound = true;
                  } // close if condition
              } // close while loop
           } // close foreach loop
           if ($wasFound == false) 
           {
               array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => $quantity,"unit_price"=>$unitprice));
           }

    }//else
    header("location:shop-cart.php?OrderId=".$orderid);
            exit();

}//if
?>

my problem is when i click on add to cart button in localhost it shows

http://localhost/mydomainname/shop-cart.php?OrderId=151011020441

but in online server it shows

http://dmainname/shop-cart.php?id=sp_gt1&unitprice=1 

and rest of the body shows blank
i want it redirects to show orderId as shown in localhost ,any help will be appreciate


Source: php

Leave a Reply