Hey guys
I have no idea why but pnRedirect does absolutely nothing for me:
pnRedirect('http://www.postnuke.com');
Nothing happens - good or bad :) (although I guess it's bad that nothing happesn)
Another module at my site is using it without problems!
Anyone know what might be wrong?
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- internetking created topic »password problem« 25. May
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 25. May
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 25. May
- ehdwma created topic »Hide "Register new account" and change template to 3 col« 25. May
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 25. May
- mdee created topic »How to implement returnpage ?« 25. May
- nestormateo responded to »Fillters in Clip« 24. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
pnRedirect
-
- Rank: Legend
- Registered: Dec 11, 2002
- Last visit: Oct 21, 2009
- Posts: 11674
pnRedirect uses the PHP header() function to perform a redirect. This will not work if you output anything to the browser before a pnRedirect call, i.e you can't use echo or anything else outputting content.
--
itbegins.co.uk - Zikula Consulting
birtwistle.me.uk - Personal Blog
Please read the Support Guide -
**unknown user**
- Rank: Registered User
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 17
I tried with this as the entire main function:
function Test_admin_main() {
pnRedirect('http://www.postnuke.com/');
return "Was not redirected";
}
And "Was not redirected" is shown :\ -
- Rank: Helper
- Registered: Jan 29, 2004
- Last visit: Oct 21, 2009
- Posts: 852
TryCode
function Test_admin_main() {
pnRedirect('http://www.postnuke.com/');
return true;
}
HTH -
- Rank: Helper
- Registered: Jan 29, 2004
- Last visit: Oct 21, 2009
- Posts: 852
Sorry, you're right. The term brain-fart comes to mind
How aboutCode
function Test_admin_main() {
return pnRedirect('http://www.postnuke.com/');
} -
**unknown user**
- Rank: Registered User
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 17
I've tried it - doesn't work.
In the Example module they do this to navigate between functions though, which is what I want to use it for, but I don't get it working for that either.
The code you wrote there outputs the "failed to load module...." message, because it doesn't return any output.
I'm starting to get angry at this thing now! :) -
- Rank: Helper
- Registered: Jan 29, 2004
- Last visit: Oct 21, 2009
- Posts: 852
What happens if you paste
Code
pnRedirect('http://www.postnuke.com/');
in your index.php just below the lines withCode
// start PN
pnInit(); -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
The important piece of info was provided by Simon. pnRedirect will not work (at all) if there has already been some output (even whitespace) by the script - actually it's if the headers have been sent back to the browser.
A simple check for this is using the headers_sent function.
Code
if (headers_sent()) {
echo 'cannot readirect as headers have already been sent';
} else {
return pnRedirect('http:://......');
}
The problem then we be indentifying where you stray output has come from; possibly an earlier debug line, whitespace before/after PHP tags etc.
-Mark
--
Visit My homepage and Zikula themes. -
**unknown user**
- Rank: Registered User
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 17
Thanks for that helpful code Mark!
I have found the source to my problem. I require_once a file which holds my database connection (not only using the PN database for this module). So at the top of pnadmin.php ICode
require_once('dbconfig.php');
I tried having only one line of code in dbconfig.php:I still have the same problem: headers are sent. I then move this line into the pnadmin.php file and replace the require_once statement, and now it works.Code
Okay, so I guess require_once is sending something, although I had no idea it did and I still don't know why it does. In any event, I guess I shouldn't be using require_once here? What's the correct way to go at it when using another database in addition to the PN database?
I really appreciate your help guys, and that goes to those who had suggestions which didn't lead to a solution also - thanks for trying! :) -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
You say that file only has the one line in it? Try putting PHP delimiters into the file i.e..Code
<?php your code ?>
-Mark
edited by: pheski, Nov 29, 2006 - 11:32 PM
--
Visit My homepage and Zikula themes. -
- Rank: Softmore
- Registered: Feb 07, 2003
- Last visit: Jun 11, 2008
- Posts: 225
Quote
Shouldn't matter what you write after the pnRedirect in any event since you should be redirected, right?
It shouldn't but it does and different browsers handle this differently (some work and some don't). Best to make sure you return true to PostNuke. -
**unknown user**
- Rank: Registered User
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 17
Mark: I already had PHP delimiters there
ctimmer: they do the same for me, none of them work (firefox, IE (new beta) and opera). In any event, postnuke doesn't want true though does it? PN wants some string of output, and true will cause it to fail loading(?)
The redirect doesn't work if I require_once the DB file with this content:
Code
and if I copy paste it over to pnadmin.php and remove the require_once statement then it works
Very little code needed to test this.. could someone have a go if this is not suppose to happen? -
- Rank: Softmore
- Registered: Feb 07, 2003
- Last visit: Jun 11, 2008
- Posts: 225
The redirect tells the browser to use a different URL.
The 'return(true)' tells PostNuke that your app has handled the browser output (in this case the redirect) and to not output anything else.
When PHP sees any kind of output, it automatically generates the required headers that will nullify your redirect. You may see an indication of this in your error log files. -
- Rank: Legend
- Registered: Dec 11, 2002
- Last visit: Oct 21, 2009
- Posts: 11674
If your MySQL connect statement is returning an error or notice, this counts as output and pnRedirect will no longer work. So, are you sure that mysql_connect() is not producing an error?
--
itbegins.co.uk - Zikula Consulting
birtwistle.me.uk - Personal Blog
Please read the Support Guide
- Moderated by:
- Support
