我在hostgator Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 64 bytes)
上收到此错误,但它在bluehost上工作正常
我有权访问php.ini,内存限制已经设置为64 memory_limit = 64M;
我无法弄清楚是这样的,请帮助。
我不知道哪部分代码会产生错误,但我提供了所有错误。
的config.php
<?php
$currency = '$'; //Currency sumbol or code
$db_username = 'root';
$db_password = '';
$db_name = 'educators';
$db_host = 'localhost';
$mysqli = new mysqli($db_host, $db_username, $db_password,$db_name);
?>
cart.php
<div class="shopping-cart">
<h2>Your Cart</h2>
<?php
if(isset($_SESSION["courses"]))
{
$total = 0;
echo '<ol>';
foreach ($_SESSION["courses"] as $cart_itm)
{
echo '<li class="cart-itm">';
echo '<span class="remove-itm"><a href="cart_update.php?removep='.$cart_itm["id"].'&return_url='.$current_url.'">×</a></span>';
echo '<h3>'.$cart_itm["title"].'</h3>';
echo '<form action="cart_update.php" method="post">
<div>No. of Participants : <input name="qty" class="qty" type="text" value="'.$cart_itm["qty"].'" />
<input type="hidden" name="course_id" value="'.$cart_itm["id"].'" />
<input type="hidden" name="return_url" value="'.$current_url.'" />
<input class="update" name="update" type="submit" value="Update" />
</div>
</form>';
echo '<div>Price :'.$currency.$cart_itm["fee"].', Subtotal: '.$currency.$cart_itm["fee"]*$cart_itm["qty"].'</div>';
echo '</li>';
$subtotal = ($cart_itm["fee"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '</ol>';
echo '<span class="check-out-txt">Total : '.$currency.$total.'</span> <a class="checkout" href="view-cart.php">Next</a> <br class="clear" />';
}else{
echo 'Your Cart is empty';
}
?>
</div>
cart_update.php
<?php
include_once("config-cart.php");
//add item in shopping cart
if(isset($_POST["type"]) && $_POST["type"]=='add')
{
$id = filter_var($_POST["id"], FILTER_SANITIZE_STRING); //course code
$return_url = $_POST["return_url"]; //return url
//MySqli query - get details of course from db using course code
$results = $mysqli->query("SELECT title,fee FROM courses WHERE id='$id' LIMIT 1");
$obj = $results->fetch_object();
if ($results) { //we have the courses info
//prepare array for the session variable
$new_courses = array(array('title'=>$obj->title, 'id'=>$id, 'qty'=>1, 'fee'=>$obj->fee));
if(isset($_SESSION["courses"])) //if we have the session
{
$found = false; //set found item to false
foreach ($_SESSION["courses"] as $cart_itm) //loop through session array
{
if($cart_itm["id"] == $id){ //the item exist in array
$qty = $cart_itm["qty"]+1; //increase the quantity
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$qty, 'fee'=>$cart_itm["fee"]);
$found = true;
}else{
//item doesn't exist in the list, just retrive old info and prepare array for session var
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$cart_itm["qty"], 'fee'=>$cart_itm["fee"]);
}
}
if($found == false) //we didn't find item in array
{
//add new user item in array
$_SESSION["courses"] = array_merge($courses, $new_courses);
}else{
//found user item in array list, and increased the quantity
$_SESSION["courses"] = $courses;
}
}else{
//create a new session var if does not exist
$_SESSION["courses"] = $new_courses;
}
}
//redirect back to original page
header('Location:'.$return_url);
}
//remove item from shopping cart
if(isset($_GET["removep"]) && isset($_GET["return_url"]) && isset($_SESSION["courses"]))
{
$id = $_GET["removep"]; //get the courses code to remove
$return_url = $_GET["return_url"]; //get return url
foreach ($_SESSION["courses"] as $cart_itm) //loop through session array var
{
if($cart_itm["id"]==$id){ //item exist in the list
//continue only if quantity is more than 1
//removing item that has 0 qty
if($cart_itm["qty"]>1)
{
$qty = $cart_itm["qty"]*0; //just decrese the quantity from -1 to *0
//prepare array for the coursess session
//$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$qty, 'fee'=>$cart_itm["fee"]);
}
}else{
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$cart_itm["qty"], 'fee'=>$cart_itm["fee"]);
}
//set session with new array values
$_SESSION["courses"] = $courses;
}
//redirect back to original page
header('Location:'.$return_url);
}
//remove item from shopping cart
if(isset($_POST["update"]) && isset($_SESSION["courses"]))
{
$id = $_POST["course_id"]; //get the courses code to remove
$return_url = $_POST["return_url"]; //get return url
foreach ($_SESSION["courses"] as $cart_itm) //loop through session array var
{
if($cart_itm["id"]==$id){ //item exist in the list
//continue only if quantity is more than 1
//removing item that has 0 qty
if($cart_itm["qty"]>=1 && $_POST['qty']>=1)
{
$qty = $_POST['qty']; //just change the quantity from 1 to qty post
//prepare array for the coursess session
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$qty, 'fee'=>$cart_itm["fee"]);
}
if($cart_itm["qty"]>=1 && $_POST['qty']=0)
{
$qty = $qty = $cart_itm["qty"]*0; //just change the quantity from 1 to qty post
//prepare array for the coursess session
//$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$qty, 'fee'=>$cart_itm["fee"]);
}
}else{
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$cart_itm["qty"], 'fee'=>$cart_itm["fee"]);
}
//set session with new array values
$_SESSION["courses"] = $courses;
}
//redirect back to original page
header('Location:'.$return_url);
}
?>
答案 0 :(得分:0)
联系hostgator支持以验证这一点,但在某些情况下,他们会为您修改php.ini或某些托管公司允许您将php.ini放在备用位置,您可以从那里设置选项。
答案 1 :(得分:0)
这篇文章太旧了,但对于使用 CentOS 具有 VPS 的某些人可能有用。我遇到了这个问题。
1。打开php.ini
CentOS:
$ nano /etc/php.ini
2。然后找到memory_limit,然后按照以下步骤将其更改为512M
CentOS:
File: /etc/php.ini
memory_limit = 512M;
如果您使用的是multiPHP,则应将相关的php.ini更改为代码使用的版本。