Using the input class of codeigniter
I recently wrote a system without security filtering input. I wanted to use the input class of CI. After analysis, there are three files required under system/core
utf8.php, security.php, input.php
Okay Integrate them into one file, but it is more troublesome. It is better to use three files, which saves trouble.
It’s like this when used:
//Instantiate the security input class
$UNI = new utf8();
$SEC = new security();
$input = new input();
Then $ username = $input->post('username').
Of course, some configuration variables need to be modified, such as $cookiepath, $cookieprefix, $cookiedomain, $cookiesecure, etc.;
But there is also a key configuration, $this->_enable_csrf= FALSE; This variable corresponds to var $ _enable_csrf= FALSE; The default is false. If you set it to TRUE,
will add the key-value pair of _csrf_token_name after the url, because this will be checked in the following code
required There must be a cookie value of _csrf_cookie_name.
Reference:
There is a csrf (Cross Site Request Forgery) protection function in CI 2.0
If this function is turned on
posting the form to the server will spit out error 500
An Error Was Encountered
The action you have requested is not allowed.
It will not be executed
At this time, you need to add a token value to the value sent by the form
In order to use the form function normally
You can find the following lines in application/config/config.php
1 2 3 4 |
|
Originally, the default value of $config['csrf_protection'] is FALSE Change it to TRUE and you can open it. After opening it, it will automatically save a value in the cookie for you. The name of the cookie can be set in the config.php mentioned above. After sending the form, you need to pass this token together.
The following Demonstration using jquery's ajax function
23456789 101112 131415161718 | $(
function $(
'#form' ) function arr = document.cookie.match( "(^| )" )); (arr !=
return null
getCookie() uses js to get the value of the cookie. And csrf_test_name is a parameter that can be set in config.php. If you have any advice, please leave a message~ referer: http://ericlbarnes.com/blog/post/codeigniter_csrf_protection_with_ajax The above introduces the input class using codeigniter, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.
|

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.
