Is there any server/hosting setting that could cause simple redirect in Yii2 to not work?
For example:
function actionIndex(){
return $this->redirect('other-page');
}
This code ends up with a blank page, no errors or messages are displayed(Error reporting is on), response code is 200 (although Yii2 debugger shows 302). Everything on my website works fine but as soon as code reaches any ->redirect() it just end up with blank page.
This happens only on my clients shared hosting (on my local machine and development shared hosting everything works just fine).
Yii2 runtime logs does not show any errors, neither server logs that my hosting is giving me access to.
It turned out that this was standard white page error: additional new blank line at the beginning of a php file.
I went through framework files, line by line. When I commented out if(headers_sent()) {return;} Yii finally threw an exception, only to let me find out that one of my config files had extra new line at the beginning of the file. Removing it fixed the problem.
Make sure that no header sent before you send redirect response.
Also check your php file encoding, if you're using UTF-8 make sure that it's UTF-8 encode without BOM.
Related
I have a vBulletin 3.8 forum.
When we click Edit button of any post (so the Quick Edit form should displayed), I get this error on the browser's console:
XML Parsing Error: xml processing instruction not at start of external entity
Location: http://www.xxxxx.xx/ajax.php?do=quickedit&p=438
Row number 2, Column 1:
... the Quick Edit form is not appearing the the progress bar displayed permanently.
I have try to disable hooks/ plugins, but the problem still appears.
I have this row on config.php: ini_set("display_errors", false); so I don't think it is a fatal error/ warning by PHP which brokes the xml normal syntax.
I have informed that this appear starts after the move of the site to another server. Does it say something to you?
Any general idea about this error?
EDIT:
Well, I found the reason of this issue, but I don't know how to fix it. Exact the same site on a localhost testing board works perfectly, but on the live server ANY html page/ ajax call etc, has a useless empty line as line #1.
For normal html pages, there is no reason for the browser to return an error, but when we're talking about an ajax call, this empty line at the top of the response, breaks the xml parsing from the browser. So it seems it is a server/ PHP/ Apache setting that applies this empty line. Any idea how to fix it? https://imgur.com/a/4neb0
It might be late for you but any new comers with php/nginx/apache can get an understanding of why.
Answer is simple: When moving the code, you might not be using git/rsync/scp but let me guess, you used zip (and probably Windows/Linux involved).
How to discover it was a two-day journey with many things tried:
We have the same error, we were also moving our servers. We tried:
We thought the server software version was a problem.
We thought the cloud provider OS image was a problem.
We used docker to avoid these problems, but the empty line problem persists.
We thought the code ?> ending was a problem, I went through all of them. But it wasn't.
I finally asked my colleague: How did you get the code? From Git? He said he downloaded from ZIP and then uploaded to server.
I removed code on the server (which extracted from a zip) and used git to download a fresh copy from our github.
Magic, problem solved. The empty line gone.
So I think the problem is with the zipping progress might have changed some file empty lines. Always use git.
I have a problem while publishing my site. I have a autentication system using session by codeigniter.
When it's run on localhost, its perfect. But when i publish in the server (hosting godaddy), It display this message
Severity: Warning
Message: session_start(): Cannot send session cookie - headers already
sent by (output started at
/home/cristiandelacruz/public_html/crmappsdc/application/config/config.php:1)
Filename: controllers/Login.php
It means you have something output on browser while redirection.
You can do following things:
1) Check which code is printing HTML. And remove it.
eg. Spaces, echo or print statements.
2) if this does not work, add ob_start (); at the file beginning. It stores output in buffer and redirection occurs.
Check if you have blank space before php opening tag in message mentioned file. Try again to save that file without BOM (Copy content into new file and double check you don't have blank space or any characters before file start and save it encoded in UTF-8 without BOM). Maybe helps.
this is happening because your local environment does not have full error reporting turned on, while your hosting provide does. The problem is most likely always there. The reason to that problem is most likely that you are calling Codeigniter's session class $this->session-> ... , however somewhere in the loading of your application, PHP already encountered this: session_start(). To fix it, you need to debug your program and find out where the session is being initialized because the way its currently set up, it is being initialized twice.
Cause:
This error is caused if the your PHP scripts are printing to the browser prior to sending headers. A common example is printing the html tags prior to starting a session, or setting a cookie. The error tells the line that needs to be altered (in this case, it is on /config.php).
Resolution:
To resolve this error remove the lines from the PHP code that are printing to the browser prior to sending headers.
Another common cause for this error is white space either at the beginning or end of the file. The fix is to remove that whitespace from the file. Read the error message carefully. It says output started at ... followed by a file name and a line number. That is the file (and line) that you need to edit. Ignore the second file name - that is only a file that included the file that has the whitespace. The first file is the one you have to edit, not the second one
Source from WHAT DO I DO WHEN I RECEIVE A PHP HEADER ERROR MESSAGE? GoDaddy Forum
Codeigniter Seesion class
I tried above all solutions. finally, I Changed output_buffering in PHP.ini (GoDaddy Server)
output_buffering = on
In PHP 5.4 version by default output_buffering has no value
I updated the PHP version 5.4 to 5.6 and in 5.6 version by default it has value 4096
Now it's working fine
I have this login script working just fine on one server but not on other and coudn't figure out why.
include_once 'include/processes.php';
$Login_Process = new Login_Process;
$Login_Process->check_status($_SERVER['SCRIPT_NAME']);
and the third line won't display the server status, the code display on my web page, and didn't go to main page. any idea may cause the issue.
thanks.
The third line isn't working, most likely, because you have a Fatal Error being generated somewhere as a result of this line:
$Login_Process = new Login_Process;
Either use ini_set to change the errors being displayed, or set up an error log. You basically need to know what the errors are, and then you can deal with them.
It could be many things, some of which may be the configuration.
The first thing I would check is the PHP version. Make sure that nothing in your scripts or your php.ini file conflict with the version of PHP you're migrating to.
After that, go through the functions you're calling and make sure nothing is deprecated in PHP on the second server.
I want to redirect to www.yahoo.com from my codeIgniter application. I write code like this :
redirect("http://www.yahoo.com");
It is working fine in my local computer (Windows vista / WAMP) but when I upload to linux server it just show blank screen and not redirect.
Try using the refresh method:
redirect('http://www.yahoo.com', 'refresh');
Blank screen normally means a fatal error somewhere. Check your logs!
And check your headers too. Curl it or use a HTTP Client to see what is being returned.
Debugging helps with these things. We are just random people on the internet without access to your computer, so without more information (hell you didnt even mention which version of CI you are using) we are all just taking guesses.
you probably want header: header('location: http://www.yahoo.com');
Try enabling error_reporting(E_ALL) to see if there are any errors that indicate output is being sent before those headers (specified by redirect()).
A common issue that I find is that the means of uploading (e.g. deploying over FileZilla) will sometimes insert lines depending on the transfer mode I guess. I've seen those same files I uploaded via FileZilla double spaced entirely. More than likely, you have an empty line at the top of your controller. Best way to find out is to edit that controller on the server (e.g. File Editor or re-download and view it) and see if this is the case.
So I just got a nasty surprise when I deployed some code I thought I'd tested. It would seem there must be some difference between my test machine and my server. The exact same code, featuring a header redirect, worked perfectly on my test machine and not at all on the server. The redirect on the server simply didn't happen, leaving a blank page as a result.
The header is called somewhere in the middle of the script - but nothing will have been output yet. It doesn't output anything until the very end of the script. Long after everything else is run. It buffers everything.
Both server and test machine are running the same PhP version, the same Apache version. Is there something in the configuration files that would allow the header to happen for one and not in the other? Is there something else going on here that would cause it to fail?
EDIT:
Here's the line that sets the header:
public function setRedirect($url) {
header('Location: '.$url);
}
And here's the code that calls that:
$url = new URL('index');
$this->layout->setRedirect($url->toString());
Where URL::toString() always generates a fully qualified domain name, in this case: http://domain/index.php?action=index
I checked both Php and Apache error logs. Nada.
Probably there was some whitespace or other form of output before the header call.
This is only work if you the ini setting output-buffering is on (or if you explicitly start output buffering, but in that case, the redirect should work in both computers).
You can confirm this by turning on error reporting.
Use Fiddler or some other client-side tool to check your headers. Determine that the Location: header is actually being sent. Also, some browsers are picky in the order that headers need to be sent.
I think the most likely explanation is that an error is causing the script to exit on your server, and you have display errors turned off (hence the blank screen). I would suggest checking the Apache error long on your server to see if PHP is putting something in there.
Otherwise you could use a browser extension like LiveHTTPHeaders (for Firefox) to see if the location header is being sent at all, or try debugging the script to see if it's even getting as far as that header call.
I think your server puts some script in your pages to track visitors and give you traffic stats or for a similar purpose. Ideally, you should get an error for this but may be your server has error reporting disabled which gives you a blank page.
I suggest you to run a script with a syntax error and check weather your server has error reporting disabled.