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

Best Way to Implement Affiliate Link Tracking in CodeIgniter 4?

$
0
0
I’m building a lightweight affiliate system using CodeIgniter 4, where users can generate and share unique referral links—similar to how GrabCash manages its Profit Links system.
I want to track the following data:
  • Clicks on each referral link
  • Source of traffic (e.g., WhatsApp, Instagram, etc.)
  • Basic analytics like IP address, timestamp, and referral ID
What’s the most efficient way to implement this in CodeIgniter without causing performance issues?
Should I handle it via middleware or use a dedicated controller for tracking logic?
Also, are there any best practices to prevent bot/fake clicks and ensure more accurate tracking?
Thanks in advance for your suggestions!

HTML6 and CSS5: What's new?

$
0
0
Hello,

Have HTML6 or CSS5 been released, but there really isn't one. After HTML5 and CSS3, development organizations have moved to a "living standard" model - that is, standards are updated continuously rather than released in fixed versions.

If you have any information on this issue, please help me. I don't know if they're released yet

Thanks you!

I want to install the CI PHP framework but facing difficulties?

$
0
0
Does anyone have a step-by-step solution for this issue?
or any related document.

Images disappear from my Website

$
0
0
Hi everyone, I’m facing an issue with my website https://chipotmenu.com/. The images placed on the site keep disappearing randomly.
Can anyone please guide me on how to fix this problem?

Unable to scroll left nav in CI4 docs

$
0
0
I would've sworn I had commented in the past about not being able to scroll in the left navigation of the CI documentation, but I'm not finding any trace of that.

Anyway, it looks like the documentation is intended for a touch interface where scrolling can be done with a finger on the screen, or maybe with a scroll wheel on a mouse. There is no scrollbar. I see this regularly these days, and I consider it an accessibility tragedy - removing (or keeping hidden) a decades-proven core usability element is an awful idea. It's maddening to need access to something and have no reasonable way to get at it. (I can force scrolling by using selection mode, but this is so imprecise that it can be difficult to get to the desired content.)

If you can see a scrollbar that allows you to access the full navigation in the CI4 docs even when multiple topics are expanded, I would be interested to know what browser you're using. I'm using Chromium-based Vivaldi.

Actually... that was probably phpList documentation I had commented on before. Clearly the CI documentation is not alone in having this problem.

Validation does not appear

$
0
0
I was facing an issue where the validation doesn't appear. The code should be make the `form-control` had the `is-invalid` class when there is an error. In my case, the validation appear on the "Session User Data", but when I check the "View Data", the validation doesn't appear on the "protected errors" (As far as I remember, it should be there).

Controller:

PHP Code:
<?php
public function register()
{
    $data = [
        'validation' => $this->validation
    
];

    return view('auth/register'$data);
}

public function 
save()
{
    if (!$this->validate([
        'username' => [
            'rules' => 'required|min_length[3]|max_length[50]|is_unique[users.username]',
            'errors' => [
                'required' => 'Username is required.',
                'min_length' => 'Username must be at least 3 characters long.',
                'max_length' => 'Username cannot exceed 50 characters.',
                'is_unique' => 'Username already exists.'
            ]
        ],
        'email' => [
            'rules' => 'required|valid_email|is_unique[users.email]',
            'errors' => [
                'required' => 'Email is required.',
                'valid_email' => 'Email must be a valid email address.',
                'is_unique' => 'Email already exists.'
            ]
        ],
        'password' => [
            'rules' => 'required|min_length[8]',
            'errors' => [
                'required' => 'Password is required.',
                'min_length' => 'Password must be at least 8 characters long.'
            ]
        ]
    ])) {
        return redirect()->to('/auth/register')->withInput();
    }

    $this->user->save([
        'username' => $this->request->getVar('username'),
        'email' => $this->request->getVar('email'),
        'password' => password_hash($this->request->getVar('password'), PASSWORD_DEFAULT)
    ]);

    session()->setFlashdata('success''Registration successful! You can now log in.');

    return redirect()->to('auth/login');


Views:

Code:
<form method="post" action="<?= base_url('auth/save'); ?>">
    <?= csrf_field(); ?>
    <div class="mb-3">
        <label for="username" class="form-label">Username</label>
        <input type="text" class="form-control <?= ($validation->hasError('username')) ? 'is-invalid' : ''; ?>" value="<?= old('username'); ?>" id="username" name="username" placeholder="Enter your username" required>
        <div class="invalid-feedback">
            <?= $validation->getError('username'); ?>
        </div>
    </div>
    <div class="mb-3">
        <label for="email" class="form-label">Email address</label>
        <input type="email" class="form-control <?= ($validation->hasError('email')) ? 'is-invalid' : ''; ?>" value="<?= old('email'); ?>" id="email" name="email" placeholder="Enter your email" required>
        <div class="invalid-feedback">
            <?= $validation->getError('email'); ?>
        </div>
    </div>
    <div class="mb-3">
        <label for="password" class="form-label">Password</label>
        <input type="password" class="form-control <?= ($validation->hasError('password')) ? 'is-invalid' : ''; ?>" id="password" name="password" placeholder="Enter your password" required>
        <div class="invalid-feedback">
            <?= $validation->getError('password'); ?>
        </div>
    </div>
    <div class="d-grid mb-3">
        <button type="submit" class="btn btn-primary">Register</button>
    </div>
    <div class="text-center">
        <a href="login" class="d-block text-decoration-none mt-2">Back to Login</a>
    </div>
</form>

Screenshot:

[Image: ZMS8JAu.png]
[Image: WHQjZbw.png]
[Image: 2q4kotF.png]

The Hidden Cost of “Innovation” By Overly Frequent Development Cycles Break

$
0
0
The tech industry's focus on rapid development cycles has led to substantial instability within the developer ecosystem, where developers are increasingly burdened as uncompensated maintainers of fragile foundations. This instability, evident in ecosystems based-on JavaScript and Python, emerges from dependency cascades that disrupt projects when critical components are deprecated or updated with breaking changes. Developers face productivity losses and technical debt as they are forced to rebuild applications, retrain on new paradigms, and rediscover previously solved issues. 
  • Why your React/Next.js/Python/SwiftUI/.NET project WILL break sooner rather than later (and ChatGPT / Claude/ Gemini will not fix it soon enough)
  • The dependency hells of NPM and PIP that are killing projects
  • How tech giants profit from developer suffering
  • Why "continuous learning and improvement" has become a psychological trap for developers
  • The real cost of "moving fast and breaking things" (mostly paid at a higher price by startups and small businesses)


https://www.youtube.com/watch?v=VaKVc4rprxg

Block IP addresses of bad visitors

$
0
0
Recently, we've noticed in the logs an increase of bad actors trying to access files that do not exist. More likely just bots looking for weaknesses.


For example: 

In our logs I see this:
CRITICAL - 2025-06-04 07:07:59 --> CodeIgniter\HTTP\Exceptions\BadRequestException: The URI you submitted has disallowed characters: "1'"1000"
[Method: GET, Route: about/1%27%221000]

CRITICAL - 2025-06-04 07:08:00 --> CodeIgniter\HTTP\Exceptions\BadRequestException: The URI you submitted has disallowed characters: "1'"1000"
[Method: GET, Route: about/index/1%27%221000]

etc... There are about 7,000 entries like this all with different iterations.
Is there a way I can block this user/bot if they hit 3 or more bad URLs?

Or, if I can get an email notification of their IP address so I can block them in our cPanel.

Thanks for your attention.

Tool bar not showing

$
0
0
I saw that other users on the forum have had similar problems. So please clarify.

The debug toolbar does not appear in any case. In fact, it never appeared in all the installations and tests I did.

My environment is new ci4, recently installed, php 8.4.8, sqlite, windows 11 etc all updated.

In the env file I have:

CI_ENVIRONMENT = development

The website https://codeigniter.com/user_guide/testi...ug-toolbar says:

"The Debug Toolbar is still under construction with several planned features not yet implemented."

So it is not working in ci4, is that it? No matter what we do, it simply will not appear? Correct?

Please clarify.

Thanks.

Heads up for users using Laragon:

$
0
0
Heads up for users using Laragon:
Today Laragon's Auto Update downloaded php 8.4.9 to my system php throws a No Input File Error!
on an application that was running fine on php 8.4.7.

I tracked down the problem and just letting you know what it was!

Auto Update is sending the php-8.4.9-NTS-Win32-vs17-x64
This Non Safe Thread PHP will not run on a Windows 11 System

It requires the php-8.4.9-Win32-vs17-x64 Thread Safe PHP

I had to turn Auto Update off and manually install the correct PHP version for it to run.
So far CodeIgniter 4.6.1 is running fine under PHP 8.4.9

curl + response body

$
0
0
Hi
I am sending a request using curl, and in response, I receive


Code:
HTTP/1.1 200 Connection established

HTTP/1.1 100 Continue
Connection: keep-alive

HTTP/1.1 202 Accepted
Vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers, Accept-Encoding
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
strict-transport-security: max-age=31536000 ; includeSubDomains
x-frame-options: DENY
Content-Type: application/json
Content-Length: 56
Date: Wed, 02 Jul 2025 18:37:21 GMT
Connection: keep-alive

{"Id":"83589c7e-bd86-4101-8d93-3f2e7954e48e"}

echo $response->getBody();  give me headers and json

Code:
HTTP/1.1 202 Accepted
Vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers, Accept-Encoding
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
strict-transport-security: max-age=31536000 ; includeSubDomains
x-frame-options: DENY
Content-Type: application/json
Content-Length: 56
Date: Wed, 02 Jul 2025 18:37:21 GMT
Connection: keep-alive
{"Id":"83589c7e-bd86-4101-8d93-3f2e7954e48e"}
Is this some kind of error in CURLRequest.php?


My suggestion

In class CURLRequest this code

       
Code:
$output = $this->sendRequest($curlOptions);

        // Set the string we want to break our response from
        $breakString = "\r\n\r\n";
       
        while (str_starts_with($output, 'HTTP/1.1 100 Continue')) {
            $output = substr($output, strpos($output, $breakString) + 4);
        }

        if (preg_match('/HTTP\/\d\.\d 200 Connection established/i', $output)) {
            $output = substr($output, strpos($output, $breakString) + 4);
        }

        // If request and response have Digest
        if (isset($this->config['auth'][2]) && $this->config['auth'][2] === 'digest' && str_contains($output, 'WWW-Authenticate: Digest')) {
            $output = substr($output, strpos($output, $breakString) + 4);
        }

        // Split out our headers and body
        $break = strpos($output, $breakString);

        if ($break !== false) {
            // Our headers
            $headers = explode("\n", substr($output, 0, $break));

            $this->setResponseHeaders($headers);

            // Our body
            $body = substr($output, $break + 4);
            $this->response->setBody($body);
        } else {
            $this->response->setBody($output);
        }

        return $this->response;

Change to

Code:
    $output = $this->sendRequest($curlOptions);
    $parts = explode("\r\n\r\n", $output);
    $body = array_pop($parts);
    $headers = array_pop($parts);
    $this->setResponseHeaders($headers);
    $this->response->setBody($body);
    return $this->response;

AbuseIPDB Module

$
0
0
I'm working on a module for CodeIgniter4 to provide ip blocking: https://github.com/grimpirate/abuseipdb

I've run into an issue where I have a migration located under modules/AbuseIpdb/Database/Migrations.

After completing the setup and creating the SQLite database (php spark db:create abuseipdb --ext db) I attempt: php spark migrate

It's my understanding from the docs that migrations are auto-detected and run across every namespace. However, in practice, that did not occur. My migrations do not run. If I move the file from modules/AbuseIpdb/Database/Migrations into app/Database/Migrations and run the migration then it works (even without changing the namespace).

What am I doing wrong here?

Table (view class) Row ID

$
0
0
Can we have table rows accept a row id ? so the output of a row can be <tr id="some_id">.....</tr>

Happy 4th Everyone

The pipe operator in PHP 8.5


AssetConnect - a powerful file management solution for CodeIgniter 4 applications

$
0
0
Introducing AssetConnect for CodeIgniter 4!

Hey team! I'm excited to share a new library I've been working on called AssetConnect - a powerful file management solution for CodeIgniter 4 applications.

What is AssetConnect?

AssetConnect is a robust file management library that allows you to associate files with any entity in your application. It provides a flexible, type-safe API for handling file uploads, storage, and retrieval with powerful features.

Key Features ✨

Entity Association: Easily attach files to any entity in your application (users, products, posts, etc.)
Collections: Organize files into logical groups with specific rules and constraints
Custom Properties: Store and retrieve metadata with your files
Type-safe API: Full IDE support with strong typing
Secure Access Control: Built-in authorization checks for file access
Filtering System: Powerful query capabilities to find exactly the files you need
Queue Integration: Background processing for file operations

Example Usage ?

PHP Code:
// Add an asset to a user
$asset $user->addAsset('/path/to/file.jpg')
    ->withCustomProperties([
        'title' => 'Profile Picture',
        'description' => 'User profile picture'
    ])
    ->toAssetCollection(ImagesCollection::class);
// Get assets from a specific collection
$images $user->getAssets(ImagesCollection::class);
// Get the URL to an asset
$url $user->getFirstAsset()->getUrl(); 


Why Use AssetConnect?

Simplified File Management: No more complex file handling code scattered throughout your application
Flexible & Extensible: Create custom collections with specific rules for different types of files
Performance Optimized: Background processing for heavy operations
Secure By Design: Built with security best practices

Documentation & Resources ?

I've created comprehensive documentation that covers everything from basic usage to advanced configurations:
Documentation: https://maniaba.github.io/asset-connect/
GitHub Repository: https://github.com/maniaba/asset-connect

Get Involved! ?

I'd love for you to try out AssetConnect in your projects and provide feedback! There are several ways to contribute:

1. Try it out: Install it in your project and let me know how it works for you
2. Report issues: Found a bug or have a suggestion? Open an issue on GitHub
3. Contribute code: Pull requests are welcome! Check out the CONTRIBUTING.md file for guidelines
4. Spread the word: If you find it useful, share it with others in the CodeIgniter community

Requirements

• PHP 8.3 or higher
• CodeIgniter 4.6 or higher
• CodeIgniter Queue

Let me know if you have any questions or need help getting started! I'm excited to see how you'll use AssetConnect in your projects! ?

Web Automation and Scraping in CodeIgniter 4

$
0
0
Hi Everyone, ?
I’m currently working on a personal project (might turn into my final year submission) where I need to automate some tasks and scrape data from external websites — basically without using any third-party API. I’m aware this is often done using cURL or libraries like Guzzle in raw PHP.
But since I’ve chosen CodeIgniter 4 for this project, I’m curious:
  • Is it a good idea to implement web scraping or automation logic directly in a CI4 controller/service?
  • Can I integrate tools like cURL or Simple HTML DOM Parser in CodeIgniter without breaking the framework structure?
  • Are there any recommended CI4-friendly libraries for scraping?
Any suggestions or examples would be really helpful. I want to make sure I’m going about this the right way. ?
Thanks in advance!

Session Not Persisting After Redirect in CodeIgniter 4

$
0
0
Hi everyone,
I’m running into a weird issue with sessions in CodeIgniter 4 and I’d really appreciate some help.

I’m setting a session value in one controller, then doing a redirect to another controller or method. I expect the session data to be available after the redirect.

The session is getting set fine, but after the redirect, the session seems empty or sometimes only partially saved. I’m using the default file-based session driver.
  • Double-checked
    Code:
    Config\App.php
    session settings — using default file handler.
  • Tried
    Code:
    session()->markAsFlashdata()
    and also regular
    Code:
    set()
    but same result.
  • Confirmed cookies are enabled.
  • Cleared cache and tried different browsers — same issue.
My questions:
  1. Is there something special I need to do to make sure sessions persist correctly after
    Code:
    return redirect()->to()
    ?
  2. Could it be a write timing issue? Do I need to manually call
    Code:
    session()->close()
    before redirecting?
  3. Are there any best practices to debug this?
Any suggestions or working examples would really help.
Thanks a lot in advance!

What's New in PHP 8.5: A Comprehensive Overview

downloading a file new tab

$
0
0
Hello. I have within a controller the option to download a file so that it can be seen in the Browser with the following command:
Code:
return $this->response->download($filename, $data], true)->inline();
The uri that calls the function or method to download the file is https://xxxxxxxx.xxx/download/docs/invoice/1 and the problem is that the title of the new open tab, corresponds to the latest segment of the URL, which is 1 and also puts the size of the unloaded file and I need to change that title to something different.
How can I do that?
Thanks in advance.
Viewing all 14346 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>