douyong1885 2014-10-16 06:38
浏览 348
已采纳

未登录时,AuthComponent成功重定向到登录页面,但某些控制器失败并显示空白页面?

I had a site in the local windows system made in cakephp. When I uploaded it to server (linux environment) the site works fine but some controllers are showing blank pages. The site works fine in local system though.

For example, when I type http://example.com/dashboard it correctly redirects back to login page but when I type http://example.com/settings it shows only blank page.

I have tried clearing tmp folder caches, renaming the controller to something else like Books, changing debug level, but neither any error shows up nor the page loads correctly. But error shows up on other pages if I make a mistake. So error reporting is working fine.

If I allow the controller action in the beforeFilter() using $this->Auth->allow() the page loads up but the codes like AuthComponenet::user('name') return empty values.

So the problem seems to be in the AuthComponenet which is successfully redirecting some pages to login and not redirecting some. And for those pages (or controllers) that it doesn't redirect it shows only a blank page irrespective of whether I am logged in or not. So what can be the possible error? The CakePHP version is 2.5.5.

Following is the AuthComponent initializing code in the AppController:

public $components = array(
    'Auth' => array(
                'loginAction' => array(
                                    'controller' => 'members',
                                    'action' => 'login'
                                ),
                'authError' => 'Did you really think you are allowed to see that?',
                'authenticate' => array(
                                    'Form' => array(
                                        'userModel' => 'Member',
                                        'fields' => array('username' => 'name','password'=>'password'),
                                        'passwordHasher' => array(
                                                            'className' => 'Simple',
                                                            'hashType' => 'md5'
                                                        )
                                    )
                                )
                ),
    'Session',
    //'DebugKit.Toolbar'
);
  • 写回答

2条回答 默认 最新

  • dtsfnyay300457 2014-10-16 09:10
    关注

    Behold the height of my stupidity...

    So as it seemed there was some problem in the AuthComponent I tried var_dumping from the AuthComponent library codes step by step to detect the problem. While doing so I noticed a peculiar thing. When the text from var_dump() is output every controller behaved the same and returned a blank page. So it became apparent that the problem was due to presence of blank spaces somewhere in the controller, because in the view source mode also one blank line was getting output:

    enter image description here

    But I had thoroughly checked and made sure there were no blank spaces or lines after the end of the Controller code. Even there were no closing ?> php tags at the end to cause the error. So where could it be? Behold my stupidity that I had an empty line just above the beginning of the Controller codes .

    enter image description here

    Clearing the empty line in the beginning solved the problem. But alas! such a silly thing took out 3 hrs of my useless time :D

    Moral of the story:

    • Make sure to check both beginning and end of files for empty space and lines when deploying code in linux systems.

    • Try some light code coloring schemes in the editor while debugging so that empty lines can be easily visible :D

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站