2013-01-31 67 views
0

是否有人可以幫助我,我試圖將這段代碼:如果用戶被阻止php包含頁面,否則包含其他?

<?php 
$blocked_users = blocked_users(); 
while ($block = mysql_fetch_array($blocked_users)) { 
if ($block['blocked'] == '1') { 
include("includes/mod_profile/mod_blocked.php"); 
} 
} 
?> 

,以適應這段代碼爲else語句:

$profile_info_set = get_profile_info(); 
while ($profile = mysql_fetch_array($profile_info_set)) 


     if (isset ($profile_id)) 
     if ($user['account_status'] == "Active") 
     if ($user['account_type'] == "Escort") { 
     include("includes/mod_profile/mod_profile.php"); 

     } 

我有一個表在我的數據庫將用戶阻止狀態從0設置爲1.如果用戶阻止某人並且該用戶試圖訪問他們的個人資料,那麼我試圖讓用戶轉到另一個說阻止的頁面。我公司通過<?php include(.. ?>

這樣做此刻我只是試圖把這個頁面的頂部:

<?php 
$blocked_users = blocked_users(); 
while ($block = mysql_fetch_array($blocked_users)) { 
if ($block['blocked'] == '1') { 
include("includes/mod_profile/mod_blocked.php"); 



       } 
} 
?> 

,而雖然它是工作,包括頁面mod_blocked.php它也帶來了mod_profile。 PHP這是默認的配置文件頁面和重疊。所以基本上如果用戶沒有被阻止,他們應該去mod_profile.php,如果用戶阻止他們去mod_blocked.php。

有人可以告訴我哪裏會出錯,怎麼做到這一點?

這裏是整個代碼頁:

<?php 
     $page_title = "Profile"; 
     include('includes/headerframe.php'); 


    // GET PROFILE ID FROM URL 
    if (isset ($_GET['id'])) { 
     $profile_id = $_GET['id']; 
    } 
    ?> 
    <?php 
    $blocked_users = blocked_users(); 
    while ($block = mysql_fetch_array($blocked_users)) { 
    if ($block['blocked'] == '1') { 
    include("includes/mod_profile/mod_blocked.php"); 



        } 
    } 
    ?> 


    <?php 
    $user_info_set = get_user_info(); 
    if (!$user = mysql_fetch_array($user_info_set)) { 
     include ('includes/mod_profile/mod_noprofile.php'); 

    } 

     else if (!isset($profile_id)) { 
         include("includes/mod_profile/mod_noprofile.php"); 
        } 

    $profile_info_set = get_profile_info(); 
    while ($profile = mysql_fetch_array($profile_info_set)) 


     if (isset ($profile_id)) 
     if ($user['account_status'] == "Active") 
     if ($user['account_type'] == "Escort") { 
         include("includes/mod_profile/mod_profile.php"); 



        } 

        else if ($block['blocked'] == '1') { 
         include("includes/mod_profile/mod_noprofile.php"); 
        } 





        $profile_info3_set = get_profile_info3(); 
    while ($profile = mysql_fetch_array($profile_info3_set)) 

     if (isset ($profile_id)) 
     if ($user['account_status'] == "Active") 
     if ($user['account_type'] == "Client") { 
         include("includes/mod_profile/mod_account.php"); 
        } 



    ?> 

回答

0

夫婦在這裏選擇。

添加breakdie()像這樣

<?php 
$blocked_users = blocked_users(); 
while ($block = mysql_fetch_array($blocked_users)) { 
if ($block['blocked'] == '1') { 
include("includes/mod_profile/mod_blocked.php"); 
break; 
} 
} 
?> 

或者,圍繞着它的else

<?php 
$page_title = "Profile"; 
include ('includes/headerframe.php'); 

// GET PROFILE ID FROM URL 
if (isset($_GET['id'])) { 
    $profile_id = $_GET['id']; 
    die(); 
} 

$blocked_users = blocked_users(); 
while ($block = mysql_fetch_array($blocked_users)) { 
    if ($block['blocked'] == '1') { 
     include ("includes/mod_profile/mod_blocked.php"); 
    } else { 
     $user_info_set = get_user_info(); 
     if (!$user = mysql_fetch_array($user_info_set)) { 
      include ('includes/mod_profile/mod_noprofile.php'); 
     } else if (!isset($profile_id)) { 
      include ("includes/mod_profile/mod_noprofile.php"); 
     } 

     $profile_info_set = get_profile_info(); 
     while ($profile = mysql_fetch_array($profile_info_set)) 

      if (isset($profile_id)) 
       if ($user['account_status'] == "Active") 
        if ($user['account_type'] == "Escort") { 
         include ("includes/mod_profile/mod_profile.php"); 
        } else if ($block['blocked'] == '1') { 
         include ("includes/mod_profile/mod_noprofile.php"); 
        } 

     $profile_info3_set = get_profile_info3(); 
     while ($profile = mysql_fetch_array($profile_info3_set)) 

      if (isset($profile_id)) 
       if ($user['account_status'] == "Active") 
        if ($user['account_type'] == "Client") { 
         include ("includes/mod_profile/mod_account.php"); 
        } 
    } 
} 
?> 
0

我不知道如果我完全理解你在做什麼,但是當我你的問題是正確的,你可以這樣做:

$page_title = "Profile"; 
include('includes/headerframe.php'); 

// stores the correct include file... 
$toInclude = false; 


// GET PROFILE ID FROM URL 
if (isset ($_GET['id'])) { 
    $profile_id = $_GET['id']; 
} 

// look up for blocked user.. 
$blocked_users = blocked_users(); 
while ($block = mysql_fetch_array($blocked_users)) { 
    if ($block['blocked'] == '1') { 
     // don't do the include inside the loop 
     // we simply set the $toInclude 
     $toInclude = "includes/mod_profile/mod_blocked.php"; 
     break; 
    } 
} 
$user_info_set = get_user_info(); 
// in case no include is set, and there is no profile... 
if (!$toInclude && (!$user = mysql_fetch_array($user_info_set) || 
    !isset($profile_id))) { 
    // we set the $toInclude now 
    $toInclude = 'includes/mod_profile/mod_noprofile.php'; 
} 


if($toInclude) { 
    // either blocked or no-profile 
    include($toInclude); 
} else { 
    // user is not blocked, and you have a profile 
    // proceed with your code for normal user handling here 
}