嗨, 我嘗試做一個小的形式爲學校和一切工作正常,因爲我做了「reorganizeVector()」函數。現在,當我想在瀏覽器上嘗試我的表單(僅此網頁)時,它會加載2〜3分鐘,並且出現Bad Gateway 502錯誤。我幾乎可以肯定我的問題是在「reorganizeVector()」函數中。我試圖找到我的功能有什麼問題,但我找不到我做錯了什麼。
,因爲它在這裏上午03點18,我會添加一些其他的文件,如「的index.php」明天,我必須早上5點的學校,所以醒來...... 錯誤的網關502等待~2min後頁面加載錯誤
這將是感激,如果你能幫助我。
請幫幫我!
B.T.W.對不起我的英語不好,我是加拿大法語,我盡力做到最好。
<?php
if(version_compare(PHP_VERSION, '5.4.0') >= 0)
{
if(session_status() == PHP_SESSION_NONE)
session_start();
}
elseif(session_id() == '')
session_start();
define('MIN_CAR', 3);
define('MAX_CAR', 30);
define('MIN_QTY', 1);
define('MAX_QTY', 1000);
if(isset($_POST['name']) AND isset($_POST['qty']) AND isset($_POST['category']))
{
$nameValide = (strlen($_POST['name'])>=MIN_CAR AND strlen($_POST['name'])<=MAX_CAR);
$qtyValide = ($_POST['qty']>=MIN_QTY AND $_POST['qty']<=MAX_QTY);
if($nameValide AND $qtyValide)
{
filter_var($_POST['qty'], FILTER_SANITIZE_NUMBER_INT);
if(!isset($_SESSION['vector']))
{
$_SESSION['vector'] = array(
array('name'=>$_POST['name'],
'qty'=>$_POST['qty'],
'cat'=>$_POST['category']));
}
else
array_push($_SESSION['vector'], array('name'=>$_POST['name'], 'qty'=>$_POST['qty'], 'cat'=>$_POST['category']));
}
else
{
if(!$nameValide)
error('invalid name (between '.MIN_CAR.' and '.MAX_CAR.' caracters)');
if(!$qtyValide)
error('invalid quantity (between '.MIN_QTY.' and '.MAX_QTY.')');
}
}
function error($text)
{
if(isset($error))
array_push($error, '<p class="error">'.$text.'</p>');
else
$error = array('<p class="error">'.$text.'</p>');
}
//THIS IS THE FUNCTION THAT CAUSE THIS ISSUE BUT I DONT KNOW WHAT IN THE FUNCTION CAUSE IT
function reorganizeVector()
{
foreach($_SESSION['vector'] as $value)
{
if(isset($array))
array_push($array, array($value['name'], $value['cat']));
else
$array = array(array($value['name'], $value['cat']));
}
$backup = $array;
$x = 1;
for($i=0; $i<sizeof($array); $i++)
{
//name qty cat
$int = null;
$index = null;
do
{
$shifted = array_shift($array);
$index = array_search($shifted, $array)+$x;
if(!empty($index))
{
if(isset($temp))
array_push($int, $index);
else
$int = array($index);
}
$x++;
}
while(!empty($index));
if(isset($temp))
array_push($temp[$x], $int);
else
$temp = array($x=>$int);
}
foreach($temp as $key => $secondary)
{
$primary = $_SESSION['vector'];
$newQty = $primary[$key]['qty'];
foreach($secondary as $index)
{
$newQty += $primary[$index]['qty'];
}
$primary[$key]['qty'] = $newQty;
if(isset($newVec))
array_push($newVec, $primary[$key]);
else
$newVec = array($primary[$key]);
}
$_SESSION['vector'] = $newVec;
}
//--------------------------------------------------------------------HTML--------------------------------------------------------------------
?>
<h2>Add an article</h2>
<?php
if(isset($error))
foreach($error as $value)
echo $value;
?>
<form method="post" action="">
<p>
<label name="name">Name :</label>
<input type="text" name="name" pattern="^.{3,30}$" title="Between <?php echo MIN_CAR.' and '.MAX_CAR; ?> caracters" required>
<br>
<label name="qty">Quantity : </label>
<input type="text" name="qty" size="4" pattern="(^(0*[1-9]{1}[0-9]{0,2})$)|(^1000$)" title="Value between <?php echo MIN_QTY.' and '.MAX_QTY; ?>" required>
</p>
<p>
<label name="category">Category :</label><br>
<input name="category" type="radio" value="kitchen" checked> Kitchen<br>
<input name="category" type="radio" value="electronic"> Electronic<br>
<input name="category" type="radio" value="other"> Other<br>
<input name="category" type="radio" value="hardware"> Hardware<br>
<input name="category" type="radio" value="sport"> Sport<br>
<br>
<button type="submit">Validate</button>
</p>
</form>
<?php
if(isset($_SESSION['vector']))
{
reorganizeVector();//<---------------------------------------FUNCTION CALLED HERE
?>
<hr>
<table border="1" style="width:400px">
<tr>
<th style="width:50%">Name</th>
<th>Quantity</th>
<th>Category</th>
</tr>
<?php
foreach($_SESSION['vector'] as $value)
{
echo '
<tr>
<td>'.$value['name'].'</td>
<td>'.$value['qty'].'</td>
<td>'.$value['cat'].'</td>
</tr>
';
}
?>
</table>
<?php
}
?>
http://stackoverflow.com/questions/3185832/suddenly-getting-a-502-bad-gateway-error?rq=1檢查此鏈接。這可能是由於您的服務器連接問題。 – Karthikeyan
即使我可以加載我網站的所有其他頁面?即使當我刪除我的reorganizeVector()函數時,一切正常嗎? – DrunkenPoney