January 29, 2025, 9:53 pm
Hi,
I got shield library as my authenticator and I have "remember me" enabled and I keep getting this error. If I forcefully logout it work. Below is the error I get on the logger. Any idea on how to fix this without touching the vendor folder.
Code:
CodeIgniter\Shield\Exceptions\LogicException: The user has User Info in Session, so already logged in or in pending login state. If a logged in user logs in again with other account, the session data of the previous user will be used as the new user. Fix your code to prevent users from logging in without logging out or delete the session data. user_id: 3
[Method: POST, Route: login]
in VENDORPATH/codeigniter4/shield/src/Authentication/Authenticators/Session.php on line 651.
1 VENDORPATH/codeigniter4/shield/src/Authentication/Authenticators/Session.php(177): CodeIgniter\Shield\Authentication\Authenticators\Session->startLogin()
2 VENDORPATH/codeigniter4/shield/src/Controllers/LoginController.php(71): CodeIgniter\Shield\Authentication\Authenticators\Session->attempt()
3 SYSTEMPATH/CodeIgniter.php(933): CodeIgniter\Shield\Controllers\LoginController->loginAction()
4 SYSTEMPATH/CodeIgniter.php(509): CodeIgniter\CodeIgniter->runController()
5 SYSTEMPATH/CodeIgniter.php(355): CodeIgniter\CodeIgniter->handleRequest()
6 SYSTEMPATH/Boot.php(334): CodeIgniter\CodeIgniter->run()
7 SYSTEMPATH/Boot.php(67): CodeIgniter\Boot::runCodeIgniter()
8 FCPATH/index.php(56): CodeIgniter\Boot::bootWeb()
↧
January 28, 2025, 7:29 pm
i got this error when install codeigniter shield.
this is my version:
codeigniter4/framework v4.2.11 The CodeIgniter framework v4
codeigniter4/settings v2.2.0 Settings library for CodeIgniter 4
codeigniter4/shield v1.1.0 Authentication and Authorization for CodeIgniter 4
Please Help
ErrorException
Undefined property: Config\Security::$csrfProtection
VENDORPATH\codeigniter4\shield\src\Authentication\Authenticators\Session.php at line 102
95 * Checks less secure Configuration.
96 */
97 private function checkSecurityConfig(): void
98 {
99 /** @var Security $securityConfig */
100 $securityConfig = config('Security');
101
102 if ($securityConfig->csrfProtection === 'cookie') {
103 throw new SecurityException(
104 'Config\Security::$csrfProtection is set to \'cookie\'.'
105 . ' Same-site attackers may bypass the CSRF protection.'
106 . ' Please set it to \'session\'.'
107 );
108 }
109 }
↧
↧
January 28, 2025, 9:53 pm
hello there,
i have a web application form that does booking
it uses a few field like client name (pulled from a database or typed manually
address
cost (computed after you put the address)
time schedule after u select from popup calendar or instant at current time
and then it submit the form
i like to have it convert to an API so i can use it from woocommerce client plugin without exposing the booking form url form on internet
lastly i need the wooclient plugin to be able to do the booking via this api.
i am willing to pay if anyone can help me with this setup.
thanks
tony
↧
January 30, 2025, 5:50 am
Hello! My issue is the following. I want to deploy my CI4 application with PHP-FPM and Apache, but I receive the following error.
Code:
[2025-01-30 13:33:55] CRITICAL: () line : Error: Class "CodeIgniter\I18n\Time" not found
To make it more interesting the following works without any errors or warning:
And php extension intl is enabled where I deploy the app and I ran composer install too.
Code:
find vendor -name *Time.php
vendor/google/common-protos/src/Type/DateTime.php
vendor/codeigniter4/framework/system/Language/en/Time.php
vendor/codeigniter4/framework/system/I18n/Time.php // <- exists
vendor/ramsey/uuid/src/Type/Time.php
I also granted privilige to the vendor folder, with no effect.
I would appreciate any help.
↧
January 30, 2025, 10:05 am
I have a problem with 4.6.0 (only tested on this version though).
I use
PHP Code:
<?= $this->include('templates/subheader', ['id' => 'werk', 'topic' => 'book']); ?>
in my view.
My subheader is something like
PHP Code:
<section class="bg-section bg-section-shadow text-black" id="<?= esc($id) ?>">
<div class="container">
<a href="<?= base_url('#top') ?>"><img src="<?= base_url('image.png') ?>" alt="Logo" class="pt-5 float-start"/></a>
<div class="text">
<div class="title">Heading here</div>
<div class="subtitle">Werk: <span><?= esc($topic) ?></span></div>
</div>
</div>
</section>
but only getting
or
PHP Code:
Undefined variable $topic
here. What I am missing?
↧
↧
January 31, 2025, 5:30 am
Code:
+----+--------------------------+---------------------+--------+
| ID | Title | Updated At | Active |
+----+--------------------------+---------------------+--------+
| 7 | A great item title | 2017-11-16 10:35:02 | 1 |
| 8 | Another great item title | 2017-11-16 13:46:54 | 0 |
+----+--------------------------+---------------------+--------+
I want do add an additional "row" in the "Updated at" cell. How would I do that with CLI::table()?
I've tried adding a "\n" followed by the additional content, but that screws up the entire table layout...
↧
January 31, 2025, 9:05 am
Code:
curl_setopt($curlh, CURLOPT_INTERFACE, "xxx.xxx.xxx.xxx");
Is there a way to use the setting in the curl library of codeigniter 4 without changing the setCURLOptions method in the HTTP\CURLRequest.php file?
The setCURLOptions function does not support this instruction.
↧
February 1, 2025, 11:11 pm
Hi all!
The MBSTRING library is deprecated, but it is also one of the minimum requirements for installation.
How can I fix it?
How do you behave?
↧
February 2, 2025, 10:56 am
I'm currently trying to debut my site and get it working again. Currently on the newest version of CI. Trying to get the debug toolbar to load, and it keeps getting blocked by a CORS error:
"login:1 Access to XMLHttpRequest at 'https://[site]/?debugbar_time=1738522321.192592' from origin 'https://www.[site]' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
I've tried numerous times to set the CORS policy via .htaccess(the one in the public directory). Below is my current file:
Code:
# Disable directory browsing
Options -Indexes
AddDefaultCharset UTF-8
AddDefaultCharset ISO-8859-1
DefaultLanguage en-us
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php?/$1 [L,NC,QSA]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
<IfModule mod_headers.c>
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE"
Header add Access-Control-Allow-Headers "Content-Type, Accept, Origin, X-Requested-With"
Header add Access-Control-Allow-Credentials "true"
Header add Access-Control-Max-Age "3600"
</IfModule>
↧
↧
February 3, 2025, 11:44 am
I'm confused on how best to proceed. I created a Model with an
$allowedFields 'date_request'. I created an Entity class that has
'date_request' as one of its
$attributes. My confusion stems from two places in the docs:
In using my
'date_request' field should I define it as a
'datetime' type in the
$casts array or should I place it into the
$dates array to mutate it automatically? Neither? Both?
What are the issues/benefits of these approaches in terms of the Entity and Time classes
?
Why bother with
$dates at all if I have the ability to mutate via cast; more peculiarly if I can specify a cast that is nullable?
↧
January 29, 2025, 4:18 pm
I would like to make a redirect from Library class in CI4. It does not work. I am changing the code from CI3 to CI4 and after I read a lot of topics regarding redirect I could not find an example for my case.
In CI3 it was easy to use redirect():
PHP Code:
redirect(base_url($redirect_url), 'location', 301);
I used these redirects and it does not work:
PHP Code:
return redirect()->to(base_url($redirect_url));
return redirect()->to($redirect_url);
I am getting an error if I use redirect()->route():
The route for URL cannot be found.
PHP Code:
return redirect()->route($redirect_url,[], 301);
This is not from Controller. I need a redirect to a different page from Library Class, which is located in APP\Libraries\LibraryFolder\LibraryClass.php
Please let me know if there is a way to make it work.
↧
February 3, 2025, 10:00 pm
Hi,
We migrated from php 5 to 7 post that we see the SMTP flow is not stable tried importing the certificate in the truststore but post that the email flow is inconsistent works sometime but fails with junk characters. The error message is not very clear on why its failing. Have masked some of the data for security reason.
Please see if there is a way to identify the issue or debug it.
Code:
function send_smtp($dest, $subject, $message, $smtp = NULL) {
if (!$smtp) {
$smtp = $this->make_smtp(false);
}
$config = array(
'protocol' => 'smtp',
'smtp_host' => $smtp['server'],
'smtp_port' => $smtp['port'],
'useragent' => "NexthinkAppliance",
'mailtype' => "html",
'newline' => "\r\n",
'crlf' => "\r\n"
);
if (strlen($smtp['login']) > 0) {
$config['smtp_user'] = $smtp['login'];
}
if (strlen($smtp['password']) > 0) {
$config['smtp_pass'] = $smtp['password'];
}
if ($smtp['tls'] === 'true') {
$config['smtp_crypto'] = 'tls';
}
$this->load->library('email', $config);
$this->email->from($smtp['from']);
$this->email->to($dest);
$this->email->subject($subject);
$this->email->message($message);
if (!$this->email->send()) {
log_message('debug', $this->email->print_debugger());
throw new Exception("Unable to send email. Check parameters");
}
log_message('debug', $this->email->print_debugger());
}
---------------
INFO - 2025-01-21 07:39:13 --> Email Class Initialized
INFO - 2025-01-21 07:39:18 --> Language file loaded: language/english/email_lang.php
DEBUG - 2025-01-21 07:39:28 --> <br /><pre>hello: 220 Authentication required
</pre>The following SMTP error was encountered: 220 Authentication required
<br /><pre>starttls: 250-SI-EXCAS2000.xx.yyyy.com Hello [xx.yyy.zzz.nnn]
250-SIZE 36700160
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250 CHUNKING
</pre>The following SMTP error was encountered: 250-SI-EXCAS2000.xx.yyyy.com Hello [xx.yyy.zzz.nnn]
250-SIZE 36700160
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250 CHUNKING
<br />The following SMTP error was encountered: .0.0 SMTP server ready
..........Mix of encoded characters that cannot be pasted...............
<br />Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.<br /><pre>Date: Tue, 21 Jan 2025 07:39:13 +0000
From: <abcd.Service@yyyy.com>
Return-Path: <abcd.Service@yyyy.com>
To: abcd.Service@de.yyyy.com, abcd.abcd@in.yyyy.com
Subject: =?UTF-8?Q?[abcd=20appliance]=20test=20email?=
Reply-To: <abcd.Service@yyyy.com>
User-Agent: abcdAppliance
X-Sender: abcd.Service@yyyy.com
X-Mailer: abcdAppliance
X-Priority: 3 (Normal)
Message-ID: <678f4f2127b14@yyyy.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_678f4f2127b21"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_678f4f2127b21
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This email has been sent from the abcd configuration console hosted on:
si0nxqa01.de.yyyy.com
--B_ALT_678f4f2127b21
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=0A<html>=0A <head>=0A <title>abcd Appliance</title>=0A </=
head>=0A <body>=0A This email has been sent from the abcd con=
figuration console hosted on: si0nxqa01.de.yyyy.com<br/>=0A </body>=0A<=
/html>
--B_ALT_678f4f2127b21--</pre>
}
↧
February 5, 2025, 4:50 am
I'm new to codeigniter 4 and i try to simply run a python code from file in controller method:
so i have following:
PHP Code:
public function runPythonScript(){
log_message('debug', 'OKKKKrun1' );
//echo shell_exec("whoami"); //by this i got: nt authority\system
$scriptPath = "C:/xampp/htdocs/ci4-test/public/assets/python/welcome.py";
//$command = "echo Hello World 2>&1";//this works properly
$command = escapeshellcmd("C:/Users/L/AppData/Local/Microsoft/WindowsApps/python.exe $scriptPath 2>&1");//returns empty and no log in python itself so does not exacuted at all
$output = shell_exec($command);
log_message('info', 'OKKKKrun2' .print_r($output,true));//this logged empty
if ($output === null) {
$error = error_get_last();
log_message('error', 'Error executing script: ' . print_r($error, true));//this logged empty
echo "An error occurred. Check the logs.";
} else {
echo 'result is: '.$output;
}
}
while the path is added to system variables and shell_exec is worked properly with in line comment as mentioned above, the welcome python code does not exacuted at all;
and any logging does not performed there;
accordingly the result of python code run is empty and i get no thing when i run code on browser other than bellow:
PHP Code:
INFO - 2025-02-05 12:41:47 --> OKKKKrun1
INFO - 2025-02-05 12:41:47 --> Python script output:
INFO - 2025-02-05 12:41:47 --> Executing command: C:/Users/L/AppData/Local/Microsoft/WindowsApps/python.exe C:/xampp/htdocs/ci4-test/public/assets/python/welcome.py 2^>^&1
INFO - 2025-02-05 12:41:47 --> OKKKKrun2
ERROR - 2025-02-05 12:41:47 --> Error executing script:
here is my python code:
PHP Code:
# welcome.py
import sys
try:
print("Welcome to CodeIgniter!")
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
and part in routs.php
PHP Code:
$routes->get('run-script', 'Properties\PropertiesController::runPythonScript');
any one can describe what is the problem and how should i reslve that?
thanks in advance
↧
↧
February 5, 2025, 5:37 am
I'm testing the functioning of the Throttle class, everything is ok, the only thing I'm wondering about is that two files are created per user in the cache folder.
Are these files automatically deleted somehow or is it necessary to create a cronjob to take care of them?
↧
February 5, 2025, 8:08 am
Based on the CodeIgniter documentation on validation, there are still a few things that are a bit unclear to me, so I wanted to ask here for advice on whether my approach is in line with best practice and how you would implement it.
https://codeigniter.com/user_guide/libra...ation.html
I have created a new class under app/Validation/NewsletterRules.php:
PHP Code:
<?php
namespace App\Validation;
class NewsletterRules
{
// Validation rules
public static $rules = [
'email' => 'required|valid_email|max_length[254]|isNotTrashmail|hasValidMxRecord',
//...
];
private function getEmailHost(string $email): string
{
$parts = explode('@', $email);
return strtolower(trim(end($parts)));
}
public function isNotTrashmail(string $str = null, ?string &$error = null): bool
{
$trashmailFilePath = WRITEPATH . 'data/trashmails.txt';
if (!file_exists($trashmailFilePath)) {
return true;
}
$trashmailList = file($trashmailFilePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$emailHost = $this->getEmailHost($str);
foreach ($trashmailList as $trashDomain) {
if (stripos($emailHost, $trashDomain) !== false) {
$error = 'Email provider not supported.';
return false;
}
}
return true;
}
public function hasValidMxRecord(string $str = null, ?string &$error = null): bool
{
$host = $this->getEmailHost($str);
if (!checkdnsrr($host, 'MX')) {
$error = 'The domain does not have a valid DNS MX record.';
return false;
}
return true;
}
}
And registered them accordingly under app/Config/Validation.php:
PHP Code:
public array $ruleSets = [
//...,
\App\Validation\NewsletterRules::class,
//...
];
Now I would do the following in the controller:
PHP Code:
$validation = service('validation');
$validation->setRules(\App\Validation\NewsletterRules::$rules);
if ($validation->run($data)) {
$validatedData = $validation->getValidated();
}
Would this be the correct / best possible procedure? Are there more elegant ways? Do you prefer the validation rules in the controller or in the model? In general, most frameworks seem to leave the validation completely to the controller?
I am also a bit confused by the statement at $validation = service('validation'); What exactly does this mean? Isn't it used in the example itself?
Quote:"You may never need to use this method, as both the Controller and the Model provide methods to make validation even easier."
Thank you very much for your thoughts!
↧
February 5, 2025, 12:24 pm
Hello,
I'm doing a large migration from CI3 to CI4. I have a bunch of CI3 code that uses
PHP Code:
//First turn off debugging so we can track errors
$this->db->db_debug = FALSE;
//do some transactions
$this->db->db_debug = TRUE;
I was able to find reference to a CI4 configuration for DBDebug,
https://codeigniter.com/user_guide/datab...ation.html, but I can't figure out how to set it. When I use:
PHP Code:
$this->db->DBDebug = FALSE;
I get an error, Cannot access protected property CodeIgniter\\Database\\MySQLi\\Connection::$DBDebug
How can I change that property in CI4?
↧
February 5, 2025, 8:20 pm
Hello,
I'm having problems trying to install CodeIgniter 4 via Composer, on a local server (xampp). Any idea what the error may be or how I can fix it?
The code that throws me is the following:
Code:
PS C:\Users\PuercoRico> cd D:\xampp\htdocs
PS D:\xampp\htdocs> composer create-project codeigniter4/appstarter ci4 -s rc
Installing codeigniter4/appstarter (4.0.0-rc.4)
- Installing codeigniter4/appstarter (4.0.0-rc.4): Loading from cache
Created project in ci4
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- codeigniter4/framework v4.0.0-rc.3 requires ext-intl * -> the requested PHP extension intl is missing from your system.
- codeigniter4/framework v4.0.0-rc.2.1 requires ext-intl * -> the requested PHP extension intl is missing from your system.
- codeigniter4/framework v4.0.0-rc.2 requires ext-intl * -> the requested PHP extension intl is missing from your system.
- codeigniter4/framework v4.0.0-rc.1 requires ext-intl * -> the requested PHP extension intl is missing from your system.
- codeigniter4/framework 4.0.0-rc.4 requires ext-intl * -> the requested PHP extension intl is missing from your system.
- Installation request for codeigniter4/framework ^4@rc -> satisfiable by codeigniter4/framework[4.0.0-rc.4, v4.0.0-rc.1, v4.0.0-rc.2, v4.0.0-rc.2.1, v4.0.0-rc.3].
To enable extensions, verify that they are enabled in your .ini files:
- D:\xampp\php\php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
↧
↧
February 5, 2025, 10:41 pm
I don't think many will answer, but I'll ask anyway. Is there any way to get rid of app/Config/* ? We're talking about duplicate configs. I would replace them with their own copies with a new namespace - App\Config - and extend the class from vendor/
This would allow the framework to be updated without changes.
But this can't be changed - we have the same namespaces. Second, we definitely need files in app/Config, the framework doesn't read them from vendor/ (probably because of the ZIP installer).
Question: I would like to replace configs from the vendor/lib/* library with new ones, but using inheritance. Any options? I want to set up a personal starter, so there are almost no restrictions.
I'm waiting:
PHP Code:
namespace App\Config;
class App extends \Config\App {}
↧
February 6, 2025, 7:12 am
I found this AI Assistant for CodeIgniter at ChatGPT and have to say that it has really helped me several times with some questions. It is also regularly updated with the latest documentation.
Maybe it will help you too
![Smile Smile]()
(free):
CodeIgniter 4 CodingAssist
↧
February 6, 2025, 9:19 am
Hello!
I'm doing a large migration from CI3 to CI4. I have a function where I'm trying to figure out if the request is from a CLI call or not
In CI3 the code used was:
PHP Code:
$this->input->is_cli_request()
In CI4, I tried using
PHP Code:
$this->request->is('cli')
But I get an error with "message": "Unknown type: cli"
How can I check for a CLI request?
Thank you!
↧