CodeIgniter redirect() error - php

When I test my CodeIgniter redirect code, the following error occurs:
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /var/www/allci/CIone/application/config/autoload.php:1)
Filename: helpers/url_helper.php
Line Number: 544
What is causing this?

Output started at (as the error says) /var/www/allci/CIone/application/config/autoload.php on line 1. This means that either autoload.php is a mixed HTML/PHP file (which it probably shouldn't be) or, more likely, autoload.php is has leading white space before it's opening <?php tag.
The < should be the first byte in the file - you need to make sure there are no spaces, tabs, carriage returns etc at the start of the file. You also need to make sure the file does not have a BOM at the start of it.

Related

Drupal - Changing decimal field in database causes errors

I needed to change the data_scale of a decimal field implemented by the module "computed field".
I changed the field_data_MYFIELD directly in database (from 10,2 to 10,4).
I also modified the field_revision_MYFIELD the same way.
As third step, I modified the data of the field_config by changing:
FROM
s:14:"data_precision";s:2:"10";s:10:"data_scale";s:1:"2";
TO
s:14:"data_precision";s:2:"10";s:10:"data_scale";s:1:"4";
As I'm trying to clear caches with drush cc all, I get the following error:
PHP Fatal error: Unsupported operand types in
DRUPAL_SITE/modules/field/field.info.class.inc on line 495
The line 495 is:
// Make sure all expected field settings are present.
$field['settings'] += field_info_field_settings($field['type']);
I enabled the error log in index.php and have the following errors:
unserialize(): Error at offset 330 of 1314 bytes in DRUPAL_SITE/modules/field/field.crud.inc on line 374
Notice: Undefined index: settings in DRUPAL_SITE/sites/all/modules/computed_field/computed_field.install on line 13
Undefined index: settings in DRUPAL_SITE/modules/field/field.info.class.inc on line 495
Fatal error: Unsupported operand types in DRUPAL_SITE/modules/field/field.info.class.inc on line 495
What am I doing wrong?
Never a good idea to alter settings via mysql directly, take a look here to do it from code : https://drupal.stackexchange.com/questions/79378/changing-a-field-type-from-integer-to-decimal/151367#151367
Instead, you could have use an hook_update to alter the field.
Thank you Clive. I did'nt paste the whole data ...apologize. The data_precision etc keys are indeed inside a database key within that string. I tested the data content into http://blog.tanist.co.uk/files/unserialize/ (as suggested) and the string is not valid ... you were right. I fixed it by changing different values of the S lenght in order to match the content of each S . After some tests, the problem is now resolved. It appears that editing the Blob data (for computed fields with php code inside) directly from phpmyadmin is not a good idea as far as it adds many additional char that doesn't match the lenght of the S. Thanks again for your help.

PHP session_start function and CLI

Function session_start used in PHP CLI print the next warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/robi/p/test.php:1) in /home/robi/p/test.php on line 2 why?
I want to log all the client entries in a variable and check this out to see if i get forgery from a specific remote address by comparing the time user last entry and current entry time! Am I doing it wrong?
here is my code:
<?php
session_start();
$client_entry = time();
$_SESSION["entries"][] = $client_entry;
$entries = $_SESSION["entries"];
$check_out = array_filter(
$entries,
function($value) use($client_entry) {
return ($value >= ($client_entry + (1 * 0.6)));
}
);
Your problem is, apart from that it makes no sense to use sessions in CLI, that output has already started prior to session_start();.
As I see in your code, you code begins directly with session_start();, I believe you have some characters before <?php. Make sure <?php is on the very first line of your file (so also no empty lines above it), and that there is nothing (such as a white space) in front of it.
This should fix this problem you are having.
The error comes from the very first line, so you should try to convert your file to utf-8 without BOM.
Quoting Wikipedia's article:
The byte order mark (BOM) is a Unicode character used to signal the endianness (byte order) of a text file or stream.
That character is sent to the output stream, so you can't redefine headers (session_start sets up a cookie in the headers).

parsing PHP error log issue – line-breaks (\n) inside the error messages

I am trying to parse PHP error log. The issue is that breaking the file by \n doesn't work.
explode(PHP_EOL, $log)
This doesn't work because there are some error messages that contain \n by itself.
How to break such file by lines then?
Extract of the problematic log:
[04-Jan-2012 21:28:48] PHP Notice: Use of undefined constant AY_FACEBOOK_TAB_URL - assumed 'AY_FACEBOOK_TAB_URL' in /var/www/[hidden]/default.layout.tpl.php on line 36
[04-Jan-2012 22:38:02] PHP Notice: Use of undefined constant AY_FACEBOOK_TAB_URL - assumed 'AY_FACEBOOK_TAB_URL' in /var/www/[hidden]/default.layout.tpl.php on line 36
[04-Jan-2012 23:43:33] PHP Warning: file_get_contents(https://graph.facebook.com/4294967295/picture?type=large): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error
in /var/www/[hidden]/result.tpl.php on line 11
[04-Jan-2012 23:43:33] PHP Notice: Undefined variable: image in /var/www/[hidden]/result.tpl.php on line 20
Notice the line break after HTTP/1.0 500 Internal Server Error.
Use regular expression to match the start of the line. It usually is a date/time (timestamp).
This code works for me:
<?php
$content = file_get_contents('/var/log/php-log.log');
var_dump(preg_split('/\[\d\d-\w{3}-\d{4}\s+\d\d:\d\d:\d\d\]/', $content));
But though i am splitting with the line-start pattern, the first result item would be empty.
Try using "\r\n" and make sure they are in between double quotes.

How to ignore session warning when include a file in php

when I am using include() with my wordpress plugin which says an error as follows.
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/wordpress3/wp-content/plugins/new/listAllItems.php:10) in /var/www/wordpress3/wp-content/themes/thesis_16/lib/functions/document.php on line 3
listallitems.php's 10 th line says
`
include_once("../../../wp-config.php");
include_once("../../../wp-load.php");
....`
How can I avoid this error.
As explained before, this is due to some text which was already sent to the browser before your session_start() statement. Check if you haven't includes spaces/characters in your script or in one of the scripts your are including.
THis could also be an encoding problem, i.e. your file is encoded in UTF-8 with BOM but your webserver is configured in another charset, so the BOM is treated as extra characters (but this problem has indeed be answered a lot of times).
This is just a quick-fix, not the right solution.
Put an "#" symbol before the command, like this...
#session_start();
That will suppress any warnings or errors. You can do that with any PHP command. But it's not a good idea in general, because you are only putting a band-aid on the issue, and not resolving the root cause, which in your case is that the session_start() is getting called after something has been output to the buffer.
I have just added in my script :
if(!session_start()){
session_start();
}
All warnings gone.
Usually this error appears when there is output before session start function. sometimes even blank space or small character, file encoding problems.

Joomla: Warning: strpos() [function.strpos]: Empty delimiter in libraries\joomla\environment\uri.php on line 162

After installing Joomla 1.5.x on an IIS 7, instead of seeing the expected sample data I see an un-styled (sample data) page and this message at the very top of the page:
Joomla: Warning: strpos() [function.strpos]: Empty delimiter in [installdir]\libraries\joomla\environment\uri.php on line 162
How can I fix that?
I'm not sure if this is a work-around or the real answer, but setting the variable $live_site = 'base URL' (ex: http://www.site.com) in [install dir]/configuration.php seems to work.

Categories