Codeigniter redirect function is having error - codeigniter

A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/adityanamansingh/kings.adityanamansingh.com/system/core/Exceptions.php:271)
Filename: helpers/url_helper.php
Line Number: 564
Backtrace:
File: /home/adityanamansingh/kings.adityanamansingh.com/application/controllers/admin/Login.php
Line: 34
Function: redirect
File: /home/adityanamansingh/kings.adityanamansingh.com/index.php
Line: 315
Function: require_once
Why am I receiving this error in my code.

It would be easy for everyone if you share your code.
You can look at this one which says
The error occurs when you have started outputting anything before
header redirect in PHP code. For example, check out any white spaces
after or before PHP tags, HTML tags printing before starting of PHP
tags or any output or debugging before the redirect function.
Also check for blank line before and after your closing php tag.
Hope it helps. Happy coding

Related

Using Python shutil.copy to overwrite a file gives asyntax error

I am trying to overwrite one .png file with another using shutil.copy, but I keep getting a syntax error. The line in question is-
shutil.copy("/var/www/vk7krj/running/yoga.png", "/var/www/vk7krj/running/run4.png")
and the error is-
File "./latlong4.py", line 63
shutil.copy("/var/www/vk7krj/running/yoga.png","/var/www/vk7krj/running/run4.png")
SyntaxError: invalid syntax
with an up-arrow under the l in shutil
I have "import shutil" and also "from shutil import copyfile" in the head of the file.
Several hours of google searching has turned up nothing, so any assistance would be great.
Problem solved- turns out the error was incorrect indentation in an if-else earlier in the script- corrected that and the syntax error went away.

How can I get better output from Artisan commands?

[Symfony\Component\Debug\Exception\FatalThrowableError] Parse
error: syntax error, unexpected 'protected' (T_PROTECTED)
That's all I get. Any chance of a class name? The line causing the error? Anything at all that would help me narrow this down?
You can check last record in /storage/logs/laravel.log file.
Also, you could use route for the command to display full exception message:
Route::get('test-my-command', function() {
Artisan::call('my:command');
});

how to read yii session in codeginiter controller. I am new to both the frameworks

Following is the code I have used :-
require(realpath(dirname(__FILE__).'/../../../email/apps/common/framework/YiiBase.php'));
$config = require(realpath(dirname(__FILE__).'/../../../email/apps/customer/config/main.php'));
Yii::createWebApplication($config);
var_dump(Yii::app()->User->id);
i am getting following error:-
Message: include(): Failed opening 'Yii.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')
Filename: framework/YiiBase.php
Line Number: 428
Be kind write full absolute path for the script that executes the code and location of the files YiiBase.php and main.php.
Solution from the creator of Yii says:
require_once('path/to/yii.php');
Yii::createWebApplication($config);
// you can access Yii::app() now as usual
$session = Yii::app()->session;
//....use session as you wish
My file that can help you start is:
// change the following paths if necessary
$yii=dirname(__FILE__).'/../yii/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
Yii::createWebApplication($config);
NOTE
Its is not recommended you use YiiBase. Use either yii or yiilite. YiiBase serves as base class and is not intended to be used directly (to the best of my kowledge). Also check paths if they real point to the file!

Magento font_color phtml error no idea where to even start

I keep getting the following error filling up my system log constantly.
2014-03-04T11:52:56+00:00 ERR (3): Notice: Undefined index: font_color in /var/www/html/waxmanenergy.co.uk/magento/app/design/frontend/default/mt_gero/template/page/html/header.phtml on line 31
Im not sure whats wrong with it or how to go about fixing it.
This is whats in line 31 on the error path within the header.phtml file
$text_color = isset($_COOKIE['textColor']) ? $_COOKIE['textColor'] : $config['font_color'];
Anyone got any heads up to what could be the issue
$config of yours do not have any index like 'font_color'. Either $config is not an array of array without 'font_color' as its key.

Why does missing "require" / "include" call error_handler an extra time?

I have a custom error handler set up using set_error_handler. When I tried to include a file that doesn't exist, PHP calls error_handler one more time than it should:
<?php
error_reporting(E_ALL | E_STRICT);
set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext){
if(error_reporting() !== 0){
echo "<br>";
echo "<br>In Custom Error Handler...";
echo "<br>Err String: ", $errstr;
echo "<br>Passing to Default Handler...";
}
return false; // allow default
});
include("/missing_file.php"); // line 11
?>
Output:
In Custom Error Handler... // this is the extra error handler call
Err String: include(/missing_file.php)
[function.include]: failed to open stream: No such file or directory
Passing to Default Handler...
// the default handler does nothing, even though error_reporting is not zero
// Next Phase:
In Custom Error Handler...
Err String: include() [function.include]: Failed
opening '/missing_file.php' for inclusion
(include_path='.:/usr/lib/php:/usr/local/lib/php')
Passing to Default
Handler...
Warning: include() [function.include]: Failed opening
'/missing_file.php' for inclusion
in
/home/yccom/public_html/apr/test.php on line 11
The same behavior is observed with require.
For example, changing line 11 to require will give this output:
In Custom Error Handler... // this is the extra error handler call
Err String: require(/missing_file.php) [function.require]: failed to
open stream: No such file or directory
Passing to Default Handler...
// the default handler does nothing, even though error_reporting is
not zero
// Next Phase:
Fatal error: require() [function.require]: Failed opening required '/missing_file.php' in /home/yccom/public_html/apr/test.php on
line 11
What may be causing the error handler's additional call?
It's quite simple, really. PHP's lifecycle consists of 4 distinct phases:
Parsing
Compilation
Scanning
Execution
for your code to be parsed, all files that are included/required need to be fetched in the first phase, to translate the code into meaningful expressions. Your file doesn't exist, so a warning is issued.
Next, the compilation phase encounters the same include statement, and tries to convert the expressions into opcodes. The file doesn't exist, so a warning is issued.
Scanning translates code into tokens, which again cannot be done for the missing include file.
Execution time... The file cannot be executed because it is missing.
Why would PHP work like this? Isn't it stupid to blunder along, eventhough a file is missing?
In a way, yes, but include is used to include files that are non-critical to the script, if you really need that file's contents, you use require (but preferably require_once). The latter emits, as you stated, a fatal error, and stops everything dead in its tracks. That's what should happen if you're depending on another file for your code to function.
The require construct issues an E_COMPILER_ERROR, which effectively halts the compiler (not unlike __halt_compiler) at a given offset(the line where the failing require statement resides).
Check these slides for more details on each of the 4 main phases.
The reason why your code emits four warnings, is simply because PHP tries to include the file four times. Try running the script from the command line, but use strace:
$ strace -o output.txt php yourScript.php
open the output file, and see the internals of the Zend engine. Pay special attention to lines that look like:
lstat("/your/path/./file.php", 0x50113add8355) = -1//0x5... ~= 0xsomeaddress
You'll see where PHP goes looking for the file: it's all its include_path directories, the cwd, /usr/share/php, probably a pear or lib directory, and the include path you explicitly set.
I've gotten the idea to do this from this site, and based on the output I got, this seems to me to be the most plausible explanation as to why you see multiple errors.

Resources