Fork me on GitHub

pnRedirect failing  Bottom

Go to page 1 - 2 [+1]:

  • I have run into something really strange. pnRedirect is failing to redirect and instead is giving me a blank white page. Here is some example code that fails in the module.

    Code

    function Exams_admin_test()
    {
        pnRedirect(pnModURL('Exams', 'admin', 'viewitems'));
        return true;
    }


    Redirects will work in other modules, but not in this one. Any ideas?
  • Try

    Code

    return pnRedirect(pnModURL('Exams', 'admin', 'viewitems'));


    --
    Under Construction!
  • I had the same problem earlier.. another problem can be that the headers are already sent

    Code

    if (headers_sent()) {
        echo 'headers are already sent';
    } else {
        return pnRedirect(pnModURL('Exams', 'admin', 'viewitems'));
    }

    Headers will be sent if you for example echo something (http://www.php.net/headers_sent)
  • Yep, that is it. Headers are being sent. Thanks Hunkpapa, now I have to figure out what is writing text out. I have some require_once statements in my code, and from reading other posts, that maybe a problem.
  • I'm stumped. I completely deleted the file this code was in, pnAdmin.php and added the following as the file

    Code

    <?php
    function Exams_admin_test()
    {
        if (headers_sent()) {
                echo 'headers are already sent';
        } else {
                pnRedirect(pnModURL('Exams', 'admin', 'viewitems'));
                return true;
        }
        //return pnRedirect(pnModURL('Exams', 'admin', 'viewitems'));
    }
    ?>


    When I try to load the function using the following URL

    http://localhost/microtextbook/index.php?module=Exams&type=admin&func=test

    I get the message,

    headers are already sent.

    Any ideas?
  • Do you maybe have a space or carriage return before the opening
  • Only a few topics down from this one we've already been through all the reasons for pnRedirect failing ;)

    http://forums.postnuke.com/index.php?name=PNphpBB2&file=viewtopic&t=47031

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • Hammerhead,

    Thanks. I had already seen that thread, but none of the suggestions helped. Anyhow, I was alble to solve the problem by reading up a bit on headers_sent(). It turns out there are two optional parameters that are very useful for tracking down this sort of problem. Here is the code I used

    Code

    function Exams_admin_test()
    {
        if (headers_sent($filename, $linename)) {
                echo "headers are already sent in $filename at $linename";
        } else {
                pnRedirect(pnModURL('Exams', 'admin', 'viewitems'));
                return true;
        }
    }


    This pointed to my pnTables.php file. I had some extra return characters after the closing ?> at the end of the file. Elimination of these fixed the problem.

    Thanks to everyone who helped on this. BTW, Andreas and I are almost finished with a major upgrade of the Exams module.
  • AbraCadaver

    Do you maybe have a space or carriage return before the opening
  • Whats the deal with the carriage returns... how do they affect the interpreter??

    --
    David Pahl
    Zikula Support Team
  • Anything outside of PHP tags is treated as HTML source code, and therefore is sent to the browser (even if it is just empty line returns). You can't send headers to the browser if you've already sent it HTML content, so blank lines at the end of files cause the header function to fail.

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • Really, even though the the file has a .php extension... it defualts to HTML outside the PHP tags... interestng... I did not know that...

    /me rethinks problems from the past.

    /me learns something today...

    /me thought I was just partying with the wife today....

    --
    David Pahl
    Zikula Support Team
  • ...but carriage returns have no purpose outside the
     tag...??

    /me still wonders...

    --
    David Pahl
    Zikula Support Team
  • The PHP parser is always in HTML mode until it his a

Go to page 1 - 2 [+1]:

This list is based on users active over the last 60 minutes.