我已经创建了一个PHP购物车,它只是不起作用的重定向。所以当我添加一个项目时,它会显示一个空白页面,但是如果你去购物车,那么该项目就在那里。这就是我存储网址的方式:
<?php
$current_url = $_SERVER['REQUEST_URI'];
$current_url = substr($current_url, 1);
$results = $conn->query("SELECT * FROM apps A INNER JOIN device D ON D.DeviceID = A.DeviceID WHERE D.DeviceName = '$os'");
if ($results) {
//output results from database
while($obj = $results->fetch_object())
{
echo "<div class=\"col-6 col-sm-6 col-lg-4\">";
echo '<form method="post" action="cart_update.php">';
echo '<h2>'.$obj->ApplicationName.'</h2>';
echo '<p>'.$obj->ApplicationDescription.'</p>';
echo '<button class="add_to_cart">Add To Cart</button>';
echo '<input type="hidden" name="product_code" value="'.$obj->ApplicationID.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form></div>';
}
}
?>
这是在购物车空了之后应该将其重定向的代码
<?php
session_start(); //start session
include_once("includes/connect.php"); //include config file
//empty cart by distroying current session
if(isset($_GET["emptycart"]) && $_GET["emptycart"]==1)
{
$return_url = $_GET["return_url"]; //return url
session_destroy();
header('Location:'.$return_url);
}
答案 0 :(得分:0)
标题位置必须包含此类空格
header('Location: '.$return_url);exit();