好的我收到此错误:
Warning: Cannot modify header information - headers already sent by (output started at
/home/content/91/9646291/html/quotesystem/cpanel/index.php:1) in
/home/content/91/9646291/html/quotesystem/cpanel/index.php on line 11
Notice: Undefined variable: content in
/home/content/91/9646291/html/quotesystem/cpanel/index.php on line 63
Warning: include() [function.include]: Filename cannot be empty in
/home/content/91/9646291/html/quotesystem/cpanel/index.php on line 63
Warning: include() [function.include]: Failed opening '' for inclusion
(include_path='.:/usr/local/php5_3/lib/php') in
/home/content/91/9646291/html/quotesystem/cpanel/index.php on line 63
这是页面上的代码:
//Check USER LOGIN IF not logged in bring to login screen else display content
if (!(checkUser())){
header('Location: /quotesystem/index.php');
}else{
//Get the user array to display data
$userArray = getUserArray();
//Make sure that the userid in the browser is the same as current loggin in user
if($userArray['user_id'] != $uid){
$content = '';
$view = (isset($_GET['view']) && $_GET['view'] != '') ? $_GET['view'] : '';
switch ($view) {
case 'list' :
$content = 'list.php';
$pageTitle = 'Customer Control Panel - View Product';
break;
case 'changepass' :
$content = 'includes/changePass.php';
$pageTitle = 'Customer Control Panel - Change Password';
break;
case 'modify' :
$content = 'includes/modify.php';
$pageTitle = 'Customer Control Panel - Modify Product';
break;
case 'detail' :
$content = 'detail.php';
$pageTitle = 'Customer Control Panel - View Product Detail';
break;
default :
$content = 'main.php';
$pageTitle = 'Customer Control Panel - View Info';
}
if(!($content) OR $content =='') {
$content = 'main.php';
$pageTitle = 'Customer Cpanl';
}
}else {
echo "Sorry this is for the customer's eyes only...you are being redirected to the <a href=\"http://www.domain.com/quotesystem\">homepage</a>. ";
}
}
include $content;
include('../admin/footer.php');
?>
流程如果用户已登录(checkUser()如果登录则返回true,否则返回false) 然后,如果当前用户ID与URL中的用户ID匹配,则显示内容。如果没有,它会显示一个消息并重定向。
答案 0 :(得分:1)
我怀疑你的实际问题是:
if($userArray['user_id'] != $uid){ // is $uid even set ever? is the $userArray set with the right user_id?
或
checkUser() // could easily be skipping the rest of the content because of this.
因为如果那些返回正确的布尔值,$ content变量将永远不会被设置,并且您将收到错误include('');
一般情况下,我建议设置测试或其较小的堂兄弟断言,以确保您获得正确的逻辑流程。此外,请尽早和广泛地设置默认值。这些步骤有助于降低调试复杂性。
答案 1 :(得分:0)
我发现翻转逻辑非常成功以及使用javascript重定向。
if (checkUser()){
Display the content
}else{
echo "<script type='text/javascript'> window.location = 'http://www.domain.com/quotesystem'</script>";
}