PHP ошибка перенаправления Loop проблема

Я искал форум, но не мог понять проблему петли страницы перенаправления PHP.

У меня есть простая страница PHP:

 <?php include('core/init.core.php');


$page_request="graph";

if (isset($_SESSION['account']['user_role']) &&
$_SESSION['account']['user_role'] =='coaching_manager' ||
$_SESSION['account']['user_role'] =='OEM'||
$_SESSION['account']['user_role'] =='GM'||
$_SESSION['account']['user_role'] =='director'||
$_SESSION['account']['user_role'] =='proactive_coaching_manager') {
$page_request="graph";
}
else
$page_request='request_form';

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

$user = get_user_on_uin(strval($_SESSION['account']['ein']));

//var_dump(mysqli_num_rows($user));
//die();

if(mysqli_num_rows($user)>0){ //if user exists in the user table in sql


//get user data from user table in sql
$user=$user->fetch_assoc();

//update user details in db
update_user_on_uin($_SESSION['account']['firstname'],
$_SESSION['account']['lastname'],
$_SESSION['account']['email'],
$_SESSION['account']['phone'],
$_SESSION['account']['ein'],
$_SESSION['account']['managerein'],
$_SESSION['account']['ouc'],
$_SESSION['account']['user_role'],
$_SESSION['account']['som'],
$_SESSION['account']['gm']);

switch ($user['user_role']){

case 'engineer':
//check if user have changed their role/ouc if yes then resetup the user
if ($_SESSION['account']['ouc']==$user['ouc']) {

if ($page_request=='request_form') {
header('Location: request-form-engineer.php');
die();
}
elseif ($page_request=='view_requests') {
header('Location: view-requests-engineer.php');
die();
}
elseif ($page_request=='view_accepted_requests') {
header('Location: view-accepted-requests.php');
die();
}
elseif ($page_request=='view_rejected_requests') {
header('Location: view-rejected-requests.php');
die();
}
elseif ($page_request=='view_coach_assigned_requests') {
header('Location: view-coachassigned-requests.php');
die();
}
elseif ($page_request=='view_completed_requests') {
header('Location: view-completed-requests.php');
die();
}
}

else{
update_user_on_uin($_SESSION['account']['firstname'],
$_SESSION['account']['lastname'],
$_SESSION['account']['email'],
$_SESSION['account']['phone'],
$_SESSION['account']['ein'],
$_SESSION['account']['managerein'],
$_SESSION['account']['ouc'],
$_SESSION['account']['user_role'],
$_SESSION['account']['som'],
$_SESSION['account']['gm']);
//header('Location: setup-account.php?message=update');
header('Location: dashboard.php');
die();
}


case 'manager':

if ($_SESSION['account']['ouc']==$user['ouc']) {

if ($page_request=='request_form') {
header('Location: request-form-om.php');
die();
}
elseif ($page_request=='view_requests') {
header('Location: view-requests-om.php');
die();
}
elseif ($page_request=='view_accepted_requests') {
header('Location: view-accepted-requests.php');
die();
}
elseif ($page_request=='view_rejected_requests') {
header('Location: view-rejected-requests.php');
die();
}
elseif ($page_request=='view_coach_assigned_requests') {
header('Location: view-coachassigned-requests.php');
die();
}
elseif ($page_request=='view_completed_requests') {
header('Location: view-completed-requests.php');
die();
}
}

else{
update_user_on_uin($_SESSION['account']['firstname'],
$_SESSION['account']['lastname'],
$_SESSION['account']['email'],
$_SESSION['account']['phone'],
$_SESSION['account']['ein'],
$_SESSION['account']['managerein'],
$_SESSION['account']['ouc'],
$_SESSION['account']['user_role'],
$_SESSION['account']['som'],
$_SESSION['account']['gm']);
//header('Location: setup-account.php?message=update');
header('Location: dashboard.php');
// header('Location: setup-account.php?message=update');
die();
}



case 'coaching_manager':

if ($_SESSION['account']['ouc']==$user['ouc']) {

if ($page_request=='request_form') {
header('Location: request-form-coaching-manager.php');
die();
}
elseif ($page_request=='view_requests') {
header('Location: view-requests-coaching-manager.php');
die();
}
elseif ($page_request=='view_accepted_requests') {
header('Location: view-accepted-requests.php');
die();
}
elseif ($page_request=='view_rejected_requests') {
header('Location: view-rejected-requests.php');
die();
}
elseif ($page_request=='view_coach_assigned_requests') {
header('Location: view-coachassigned-requests.php');
die();
}
elseif ($page_request=='view_completed_requests') {
header('Location: view-completed-requests.php');
die();
}
elseif ($page_request=='graph') {
header('Location: graph.php');
die();
}

}

else{
update_user_on_uin($_SESSION['account']['firstname'],
$_SESSION['account']['lastname'],
$_SESSION['account']['email'],
$_SESSION['account']['phone'],
$_SESSION['account']['ein'],
$_SESSION['account']['managerein'],
$_SESSION['account']['ouc'],
$_SESSION['account']['user_role'],
$_SESSION['account']['som'],
$_SESSION['account']['gm']);
//header('Location: setup-account.php?message=update');
header('Location: dashboard.php');
//header('Location: setup-account.php?message=update');
die();
}


case 'coach':

if ($_SESSION['account']['ouc']==$user['ouc']) {

if ($page_request=='request_form') {
header('Location: request-form-coach.php');
die();
}
elseif ($page_request=='view_requests') {
header('Location: view-requests-coach.php');
die();
}
elseif ($page_request=='view_accepted_requests') {
header('Location: view-accepted-requests.php');
die();
}
elseif ($page_request=='view_rejected_requests') {
header('Location: view-rejected-requests.php');
die();
}
elseif ($page_request=='view_coach_assigned_requests') {
header('Location: view-coachassigned-requests.php');
die();
}
elseif ($page_request=='view_completed_requests') {
header('Location: view-completed-requests.php');
die();
}

}

else{
update_user_on_uin($_SESSION['account']['firstname'],
$_SESSION['account']['lastname'],
$_SESSION['account']['email'],
$_SESSION['account']['phone'],
$_SESSION['account']['ein'],
$_SESSION['account']['managerein'],
$_SESSION['account']['ouc'],
$_SESSION['account']['user_role'],
$_SESSION['account']['som'],
$_SESSION['account']['gm']);
//header('Location: setup-account.php?message=update');
header('Location: dashboard.php');
//header('Location: setup-account.php?message=update');
die();
}


default:
break;


}//end of switch

}   //end of if block

else{
//header('Location: setup-account.php?message=new_user');
//var_dump("expression");
// die();
if( insert_user($_SESSION['account']['firstname'],
$_SESSION['account']['lastname'],
$_SESSION['account']['email'],
$_SESSION['account']['phone'],
$_SESSION['account']['ein'],
$_SESSION['account']['managerein'],
$_SESSION['account']['ouc'],
$_SESSION['account']['user_role'],
$_SESSION['account']['som'],
$_SESSION['account']['gm']) )
{


header("Location: dashboard.php");
die();

}
else
{
var_dump('Sorry we do not recognise you. bye!');
die();
}
// header("Location: dashboard.php");
// die(); */

}


//if no, redirect to role selection page
?>

Имя этой страницы dashboard.php
init.core.php Страница начинает сеанс.

Задача проста. Если пользователь найден, обновите данные пользователя с помощью $_Session подробности. Если нет, то добавьте нового пользователя и перенаправьте на эту страницу для отображения соответствующей информации. Я вижу, что он выполняет остальную часть, то есть вставляет пользователя, но он вставляет много записей в базу данных, прежде чем в конечном итоге отказаться от утверждения ERR_TOO_MANY_REDIRECTS

Куда я иду не так?

-1

Решение

Я не вижу, где вы устанавливаете значение для $_SESSION['account']['id'], Без этого он будет всегда идти к первичному другому и вставлять нового пользователя.

Как говорится, ты звонишь session_start() в начале сценария? Если нет, то значения не будут поддерживаться между вызовами скрипта.

1

Другие решения

Вы пропустили скобки для корпуса переключателя.

$user = get_user_on_id(strval($_SESSION['account']['id']));
if (mysqli_num_rows($user) > 0){ //if user exists in the user table in sql
//get user data from user table in sql
$user = $user->fetch_assoc();
//update user details with current details in db
update_user_on_uin($_SESSION['account']['firstname'],
$_SESSION['account']['lastname'],
$_SESSION['account']['email'],
$_SESSION['account']['id'],
$_SESSION['account']['user_role']
);
switch ($user['user_role']){
case 'engineer': {
//check if user have changed their department if yes then update user details
if ($_SESSION['account']['ouc'] == $user['ouc']){
if ($page_request == 'request_form'){
header('Location: request-form-engineer.php');
die();
}
}
else{
update_user_on_uin($_SESSION['account']['firstname'],
$_SESSION['account']['lastname'],
$_SESSION['account']['email'],
$_SESSION['account']['id'],
$_SESSION['account']['user_role']
);
header('Location: dashboard.php');
die();
}
} //case engineer
}
}//end of switch
else{
if (insert_user($_SESSION['account']['firstname'],
$_SESSION['account']['lastname'],
$_SESSION['account']['email'],
$_SESSION['account']['id'],
$_SESSION['account']['ouc'],
$_SESSION['account']['user_role']
)){
header("Location: dashboard.php");
die();
}
else{
var_dump('Sorry we do not recognise you. bye!');
die();
}
}
-3

По вопросам рекламы [email protected]