Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all 14346 articles
Browse latest View live

Hot to throw 404 exception on accessing via index.php?

$
0
0
Hi!
I wish to make it so, that when anyone accesses my site, via mysite.com/index.php or mysite.com/index.php/existing-page they would get 404.
By default it works so that if you go to mysite/index.php you get to / and if to mysite.com/index.php/existing-page you get /existing-page.
What I did:
- Set public string $indexPage = ''; in Config/App.php
- Read through https://codeigniter.com/user_guide and searched https://forum.codeigniter.com/
- Found this rule for .htaccess (below), but it redirects /index.php/existing-page to /existing-page (which the best solution so far):
# Remove index.php from URL
RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.*)$ $1 [R=301,NS,L]
Also, maybe I'm using CI4 in a wrong way? I'm new to the framework. I want to set some concrete rewrites like mysite.com,  mysite.com/about,  mysite.com/shop, etc. All else yields you 404.
Thank you very to anyone who would help me

Shield v1.2.0 released!

$
0
0
CodeIgniter Shield v1.2.0 Released!
This update brings several usability improvements, developer conveniences, and localization updates.

Key Enhancements
  • User Relations Made Easier – The User entity now supports convenient loading of related groups and permissions, reducing the number of additional queries and improving performance.
  • Access Token Expiration – Support has been added for setting expiration dates on access tokens and HMAC keys, giving developers better control over token lifecycles.
  • Simplified User Creation – A new UserModel::createNewUser() method provides a convenient way to create a new User entity, helping to centralize and standardize user creation logic. It is now used by RegisterController.
  • Improved CLI Workflow – The shield:user create command now accepts a -g option, allowing you to assign a user to a group during creation, saving time and reducing the need for additional commands.
  • Smarter Email Templates – Email templates now expose the $user object, allowing you to personalize notifications with detailed user information.

Bug Fixes
Various bugs were fixed to improve stability, error handling, and expected behavior.

Updated Languages
German ??, Persian ??, Japanese ??, Turkish ??, Dutch ??, Brazilian ??

See the release notes for details: https://github.com/codeigniter4/shield/r...tag/v1.2.0

Full changelog: https://github.com/codeigniter4/shield/c...0...v1.2.0


Shield is the official authentication and authorization framework for CodeIgniter 4.

See https://shield.codeigniter.com/

Check urls for css class

$
0
0
Good Morning,

First, i have to appologize, my english is not the best.
second, i have a question.

I wish to check if the url is the current url, and if it's the case, the class "active", activate, and if not, well, it does not activate.

I Don't know if my question is correctly asked?
sorry if not, like i said, my english is not really the best.

Is codeigniter safe and reliable for basic projects?

$
0
0
Can I reliably use CodeIgniter without running into major compatibility issues on my system?

GMail Module

$
0
0
Created a module for using GMail's OAuth API to send out emails using CodeIgniter's email service:

grimpirate/ci4-module-gmail

A fellow developer was having a problem where their provider (DigitalOcean) implemented a blanket policy disallowing use of mail, sendmail or standard SMTP ports i.e.: they placed the onus on their webmasters to utilize an external service for email functions. Essentially pigeonholing developers into using an API (they also suggest that if the external provider allows for it to use a different port for SMTP i.e. 2525). Most email services are paid or offer a free trial period. There are few that don't use the standard ports or restrict email sends heavily in terms of rates and volumes.

That lead us to make an attempt at figuring out the GMail API. Documentation online was sparse and left much to be desired. The gmail/apiclient PHP library is also extremely terse. After assorted research I derived an implementation that functioned (exclusively for sending emails) and overrides/extends the core email service in CodeIgniter increasing its functionality with some new methods to allow the usage of GMail's API.

For this module to work you need OAuth credentials from a Google Cloud project that enables the GMail API. These credentials can be downloaded as a json file and placed into the Config folder of the module. On first use you will be directed to the google services auth page wherein you can authorize a particular gmail account to use the application to send emails on your behalf. After authorizing you are returned to your redirect URI with a code and can now request an OAuth token. The current token and its refresh token are saved to a tokens.json file within the module's Config folder.

Read session file

$
0
0
Hai, im just working session with file handler, and i have the issue
when the ccokie session has been expires as delete, the session ci cannot read session, but the session file in WRITEPATH . session still there with the cookie name and last session id, maybe ci check cookie session at first.
What solution of this ? session file is still there and will become populate because not trigger session destroy before.
how about read session file, when i can read this file session, and parse it like session that will be great

CodeIgniter Shield access groups

$
0
0
I have an application that I'm writing where I'm using CodeIgniter Shield for authentication. I want my views to look different based on the permission level and was wondering if there is a preferred way to go about doing so. Currently,  in my view, I'm using:   

<?php if(auth()->user()->can('teamlead.all')) ?>  
      Edit button, Delete button, etc.

to change what is displayed. (I handle access restrictions to my routes separately in my controllers if anyone's wondering).

How to create sitemap in CI4

$
0
0
Hello all, I am new to CI 4. Previously I was just making simple websites without frameworks and now I understand routing and frameworks little. Do you just create a route for /sitemap and return view sitmap.xml ?

ODBC in CI4

$
0
0
Hello,
Is ODBC going to be added anytime soon, or is there any plan to?
I just built this whole thing and now I find out the driver is not supported. I now see it is in "requirements" so it is my own fault for just assuming it would be continued from 3 to 4,
is there anything I can do besides downgrading to v3?
I really liked Shield
sheeesh

Can't redirect when method is called from constructor

$
0
0
Hello, I can't seem to be able to redirect users when the method is being called from the constructor of the class.
This is my controller:
PHP Code:
<?php

namespace App\Controllers;

class 
Admin extends BaseController
{
 public function 
__construct()
 {
 
$this->redirectToLogin();
 }
 
 public function 
redirectToLogin(){
 return 
redirect()->to("/admin/login");
 }

    public function index()
    {
 return 
"test123";
    }

 public function 
login(){
 return 
"test231";
 }


The
Code:
redirectToLogin()
method is being called from the constructor (I checked with xdebug) but it is ultimately not redirecting the user.
I followed this example: https://stackoverflow.com/questions/6047...eigniter-4

CI update Version 2 to version 4

$
0
0
Currently I m working on big projects since last 7 year  which in CI 2 . It’s difficult to migrate whole projects in CI 4 after update php 8 it’s giving error deceptive error msg 
Please suggest easy way for do migration CI 2 to CI 4

Database query question

$
0
0
Hello everyone,
I have decided to start programming again.
Unfortunately, I am totally out of touch with the subject.
I downloaded CI4 and now I'm trying to get a loop from the database.
But unfortunately I just don't understand how to do it.
Can anyone help me?

Help required with older version.

$
0
0
Greetings,
In 2017 we hired a guy to build a Codeigniter project to do a simple billing application.
This application was hosted on a Godaddy server.
in 2021, User of this app forgot the login password, so I edited controller to bypass validation.
Project was working fine until recent changes by Godaddy server php version.
I rolled back to the previous versions.
It allows to enter credential but throws an username password is match error.
So I added base url path even if throws error in Validation JS.
Now it loads base url after validation. It doesn't load dashboard like earlier.
Those who were involved in the project are not available anymore to help. 
I have a very basic understanding of php, js and html. Learning Codeigniter is a very difficult task at this moment.
I have full access to file manager and php-myadmin.
Any help is appreciated to make it work again.
Please let me know what details should I share.
Thanks and Regards.

CodeIgniter 4.6.2 Released – Security Strengthened, Stability Enhanced!

$
0
0
The CodeIgniter team is proud to announce the release of v4.6.2, a maintenance update that packs important security fixes, bug squashes, and a wave of internal refinements to keep your projects smooth, secure, and future-ready.

Security Fix: ImageMagick Handler Vulnerability Patched

A critical vulnerability in the ImageMagickHandler class has been patched. Previously, malicious filenames containing shell metacharacters could be exploited when using the resize() or text() methods. This has now been addressed to ensure safe image handling.


? View Security Advisory
?️ Special thanks to @vicevirus for responsibly disclosing the issue!

Notable Bug Fixes

This release includes over a dozen bug fixes aimed at improving developer experience and runtime stability:
  • Fixed corrupted cache file handling in FileHandler
  • Improved CURLRequest’s handling of intermediate HTTP responses
  • Fixed encapsulation issues in BasePreparedQuery
  • Better support for multibyte folder names in subfolder deployments
  • make:test generator now works flawlessly on Windows and produces correctly named test classes
  • Improved logic in helpers like sanitize_filename() and when()/whenNot() using native PHP truthiness

And many more fixes to email, URI handling, and content disposition headers.

Internal Refactoring & Cleanup

This version also includes sweeping internal improvements:
  • Introduced system/util_bootstrap.php to reduce tight coupling in testing bootstraps
  • Improved PHPDoc accuracy across components (Cookies, Logging, Cache, Autoloader)
  • Resolved dozens of static analysis issues (e.g., PHPStan violations, redundant ternaries)
  • Micro-optimized utility classes like Console and Format

These changes pave the way for stronger type safety, better tooling support, and more maintainable code.

Upgrade Now

Ready to upgrade? Simply follow the upgrade guide

CodeIgniter Translations v4.6.2 is also released! Upgrade now.

PHP version issues from 4.6.1 to 4.6.2

$
0
0
I updated from CI 4.6.1 to 4.6.2 locally I use php 8.3 while online I still have 8.2, after the online update it gives me the error:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.3.0". You are running 8.2.15. in /var/www/html/vendor/composer/platform_check.php on line 26
If I look in composer.json I see:
Code:
"require": {
        "php": "^8.1",
        "ext-intl": "*",
        "ext-mbstring": "*",
        "laminas/laminas-escaper": "^2.17",
        "psr/log": "^3.0"
    },
but I believe it's maennchen/zipstream-php that requires version 8.3, how can I get version 4.6.2 working online where I currently can't upgrade to 8.3?

Vulnerability reported by composer for CI 4.6.2

$
0
0
I'm sure it will be fixed soon, but I'm just reporting it.

Code:
Found 1 security vulnerability advisory affecting 1 package:
+-------------------+----------------------------------------------------------------------------------+
| Package          | codeigniter4/framework                                                          |
| Severity          | medium                                                                          |
| CVE              | CVE-2025-45406                                                                  |
| Title            | CodeIgniter4 Cross-Site Scripting Vulnerability in debugbar_time Parameter      |
| URL              | https://github.com/advisories/GHSA-49jm-g4m8-x53p                                |
| Affected versions | <=4.6.2                                                                          |
| Reported at      | 2025-07-25T18:30:41+00:00                                                        |
+-------------------+----------------------------------------------------------------------------------+

Thank you for your work

Video not playing in safari from WRITEPATH/uploads folder

$
0
0
Hi 
I have created route to display the image and video files from WRITEPATH/uploads  folder. It's working fine in chrome both images and videos are showing, but in safari browser, images are  showing but video is not playing.
PHP Code:
$routes->get('uploads/(:segment)',              'Api\AuthController::displayFile/$1'); 
below is my function to show the files.
PHP Code:
    public function displayFile($filename)
    {
        $path WRITEPATH 'uploads/' $filename;

        if (!file_exists($path)) {
            throw new \CodeIgniter\Exceptions\PageNotFoundException("File not found: $filename");
        }

        $mimeType mime_content_type($path);
        header('Content-Type: ' $mimeType);
        header('Content-Length: ' filesize($path));

        // Output the image
        readfile($path);
        exit;
    
If  I upload the same video in public path, then it displays in safari, but not working from WRITEPATH/uploads  folder. Please guide whats the issue, and how can I display the video files in safari.
Thanks

Problems sending emails in CI 4.6.2

$
0
0
I updated my app to version 4.6.2 and now I'm having problems sending, the email starts but in the console I get errors like:
Code:
<b>Fatal error</b>:  Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/xxxxxx/Sites/website/vendor/codeigniter4/framework/system/Format/JSONFormatter.php:47
Stack trace:
#0 /Users/xxxxxx/Sites/website/vendor/codeigniter4/framework/system/Format/JSONFormatter.php(47): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/xxxxxx/Sites/website/vendor/codeigniter4/framework/system/API/ResponseTrait.php(347): CodeIgniter\Format\JSONFormatter-&gt;format(Array)
#2 /Users/xxxxxx/Sites/website/vendor/codeigniter4/framework/system/API/ResponseTrait.php(106): CodeIgniter\Debug\ExceptionHandler-&gt;format(Array)
#3 /Users/xxxxxx/Sites/website/vendor/codeigniter4/framework/system/Debug/ExceptionHandler.php(85): CodeIgniter\Debug\ExceptionHandler-&gt;respond(Array, 500)
#4 /Users/xxxxxx/Sites/website/vendor/codeigniter4/framework/system/Debug/Exceptions.php(162): CodeIgniter\Debug\ExceptionHandler-&gt;handle(Object(TypeError), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions-&gt;exceptionHandler(Object(TypeError))
#6 {main}
  thrown in <b>/Users/xxxxxx/Sites/website/vendor/codeigniter4/framework/system/Format/JSONFormatter.php</b> on line <b>47</b><br />

After some testing, I set $SMTPKeepAlive to true and the error disappeared. Have there been any changes? Why is this happening now?

I also have a problem with attachments, if I do as usual:

PHP Code:
$email->attach($attach); 
it gives me the error: Undefined array key "cid"

What do I need to change to get it working again?

Localhost not responding to code changes until I restart VS Code

$
0
0
I'm trying to work on a project I started on my iMac on my MacBook Pro. I'm using Vite, but when I run develop, localhost will only display the code I had when I opened VS Code. Code changes are not reflected at all. Refreshing the page, clearing the cache, and restarting Vite all have no effect. The only way I can get the site to update is by quitting VS Code and restarting it. I can't find any similar problems online, so I don't know what to try.
Some More Details:

Node v20.18.0

Vite 5.4.2

VS Code Version: 1.94.2 (Universal)

Chrome Version 129.0.6668.101 (Official Build) (x86_64)
MacBook Pro 2017

I just installed everything on my laptop, so that may be related.

The site is frontend only and fully functional on the first load.

Please let me know if there are any more details needed.

CI4 basic framework with database

$
0
0
Hello everyone,
can someone please create a basic structure in CI4 for me?
Because I just don't know what to do.

On a prepared page there is a HTML-table where a "foreach" should be placed below, which should output the data from a table in the DB.
An insert is to take place on the top HTML table.
The "foreach" line should have two buttons on the right.
The red one should delete the selected table and the blue one should go to a page where you can edit the data with the help of a GET.

What would it cost me if someone wrote this for me and how long would it take?

Translated with DeepL.com (free version)
Viewing all 14346 articles
Browse latest View live