Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:44:49+00:00 2026-06-11T08:44:49+00:00

I know how to enable CSRF in forms in CodeIgniter, however I am not

  • 0

I know how to enable CSRF in forms in CodeIgniter, however I am not sure how to implement this feature in CodeIgniter classic link (e.g. for adding/deleting private messages, posts etc. in admin area)

Now I am using something like this:

VIEW

<?php echo anchor('account/delete_private_message/'.$obj->pmID, 'delete mesage', array('onclick' => 'return confirm(\'Do you really want to delete this private message?\');', 'class' => 'delete-message-button')); ?>

CONTROLLER

function delete_private_message($pmID = '')
    {

        $deleted_pm = $this->account_model->delete_pm($pmID);

        if($deleted_pm)
        {
            $this->session->set_flashdata('status', 'PM was deleted successfully');
        }
        else
        {
            $this->session->set_flashdata('status', 'Error');
        }
        redirect('account/private_messages');
    }

MODEL

function delete_pm($pmID)
    {

        $return = 0;
        if(!empty($pmID))
        {
            $this->db->where('pmID', $pmID);
            $result = $this->db->delete('private_messages');
        }
        return $result;
    }

And if user click on OK in the popup the message is deleted.

The question is how to add token to the link and to the session of the user and verify it etc. I do not know how to achieve this to work properly.

EDIT: I just guess I have to add the generated token at the end of the link like:

account/delete_private_message/1239/dfdf6e7re67a6e87r6e87r69876bn3

and the value dfdf6e7re67a6e87r6e87r69876bn3 also in the session of the current user and verify them in controller. However, what ecxactly should I do, I don’t know. So, any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:44:50+00:00Added an answer on June 11, 2026 at 8:44 am

    You are correct – just pass the CSRF token as part of the link. The example below should help (but I havent tested it)

    function delete_private_message($pmID = '', $token = null)
    {
        // Check supplied token is valid
        if ( ! ($this->_check_token($token)))
        {
            // Not valid
            $this->session->set_flashdata('status', 'Error');
            redirect('account/private_messages');
        }
    
    
        if($this->account_model->delete_pm($pmID))
        {
            $this->session->set_flashdata('status', 'PM was deleted successfully');
        }
        else
        {
            $this->session->set_flashdata('status', 'Error');
        }
        redirect('account/private_messages');
    }
    
    
    function _check_token ($token)
    {
          return ($token === $_COOKIE[$this->csrf_cookie_name]);
    }
    

    p.s. you have an error in your model code

    $return = 0;
    

    should be

    $result = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone know if its possible to enable horizontal scrolling ONLY in a windows forms
Is there any way to know in Servlet is JS is enable or not
I thought this was on the way, anybody know how to enable it? Seems
I'm using this plugin, I know it's not the best, but I don't have
I want to know if user account enable. I use this code: var usersList
Does anyone know how to enable or disable programmatically the Quick Edit Mode in
Does anybody know how I can enable line numbers for Ruby (and Ruby on
does sy know why the Ajax Enable WebAppication in VS 2008, even if you
I would like to know the code which can enable me to get a
I want to know what is the way to enable and disable internet connection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.