问题描述:

I'm using Ion Auth and trying to implement the forgotten password feature which relies upon an email being sent from CI. My LAMP server is on a shared cPanel account and uses sendmail. However, I have the ability to over-ride any PHP settings with my own php.ini file in the public_html directory.

As per the CodeIgniter 2 documentation for configuring email sending, I have done the following...

1) created a file called located at application/config/email.php

2) email.php contains this code:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*

| -------------------------------------------------------------------

| EMAIL SENDING SETTINGS

| -------------------------------------------------------------------

*/

$config['protocol'] = 'sendmail';

/* End of file email.php */

/* Location: ./application/config/email.php */

3) The in the application/config/ion_auth.php file, I set this value to TRUE

$config['use_ci_email'] = TRUE;

The email is successfully sent, but I get a variety of PHP Error Warnings on all pages.

These appear on all pages, sometimes two or three times in a row:

A PHP Error was encountered

Severity: Warning

Message: date() [function.date]: It is not safe to rely on the

system's timezone settings. You are required to use the

date.timezone setting or the date_default_timezone_set() function. In

case you used any of those methods and you are still getting this

warning, you most likely misspelled the timezone identifier. We

selected 'America/New_York' for 'EST/-5.0/no DST' instead

Filename: libraries/Email.php

Line Number: 704

A PHP Error was encountered

Severity: Warning

Message: date() [function.date]: It is not safe to rely on the

system's timezone settings. You are required to use the

date.timezone setting or the date_default_timezone_set() function. In

case you used any of those methods and you are still getting this

warning, you most likely misspelled the timezone identifier. We

selected 'America/New_York' for 'EST/-5.0/no DST' instead

Filename: libraries/Email.php

Line Number: 709

In addition to the above, these two also show up after the forgotten password form is submitted:

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by

(output started at

/home/username/codeigniter/system/core/Exceptions.php:185)

Filename: libraries/Session.php

Line Number: 675

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by

(output started at

/home/username/codeigniter/system/core/Exceptions.php:185)

Filename: helpers/url_helper.php

Line Number: 540

I'm not sure why I would be getting these Error Warnings or how else I am supposed to configure my email sending options. I don't see any other email sending options in the documentation that is related to these particular Warning Messages. When I remove my config/email.php file AND set Ion Auth's use_ci_email to FALSE, the Error Warnings go away.

Where did I go wrong?

网友答案:

This has nothing to do with CI. PHP requires that you set the setting date.timezone.

See http://php.net/manual/en/datetime.configuration.php#ini.date.timezone

网友答案:

One thing it's odd is the location of php.ini. I mean, in public_html folder means php.ini might be readable by the world which might not be the best of ideas.

Anyway, one way to troubleshoot this is creating a test.php file in your public_html folder with only phpinfo(INFO_CONFIGURATION); and check the settings (like include_path or allow_url_fopen). Then create a php.ini in the same folder (with some settings like allow_url_fopen) and see if anything has changed in phpinfo(INFO_CONFIGURATION).

My guess is that either:

  • public_html/.htaccess file is telling Apache to read php settings from a php.ini file located at the public_html folder.
  • your hosting provider has cpanel with mod_suphp (very common). suPHP, by default, allows each user to set their own php.ini as they see fit. It overrides sustem's php.ini.

See this link and this one


In any case, you can tweak php.ini settings without overriding it completely by either:

  • Set settings in your accounts root .htaccess
  • create a script that reads and applies settings

Keep in mind that only runtime settings that are marked as PHP_INI_ALL can be overriden this way. See this link for more info on settings mode and this for a comprehensive list of changeable php.ini settings


The first way is very straight forward:

.htaccess file

<IfModule mod_php5.c>
  php_value date.timezone "Europe/Lisbon"
  php_admin_flag engine on
</IfModule>

The second uses a custom phpini.file

  1. Create a file called myphpini.ini (or something) and place your custom settings there.
  2. Then create file called configphp.php (or something) that reads myphpini.ini
  3. Include configphp.php at the top of your scripts (or in CI2 bootstrap file)

configphp.php

$config = parse_ini_file('myphpini.ini);
foreach ($config as $key => $val) {
    print 'before->' . ini_get($key) . '<br/>';
    ini_set($key, $val);
    print 'after->' . ini_get($key) . '<br/>';
}

keep us posted on how it turned out

网友答案:

I should have never created my own custom php.ini file. I constructed it improperly and I placed it in the wrong location. Despite thinking that I knew the problem when I posted the question, I did not. My bad php.ini file was the root source of this issue all along.

相关阅读:
Top