Skip to content

Instantly share code, notes, and snippets.

@narfbg
narfbg / fv_callable_rules.patch
Created March 5, 2014 14:38
Experimental callable rules for CI_Form_validation
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 0c4f949..0a80888 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -144,7 +144,7 @@ class CI_Form_validation {
* Set Rules
*
* This function takes an array of field names and validation
- * rules as input, any custom error messages, validates the info,
+ * rules as input, any custom error messages, validates the info,
@narfbg
narfbg / PHP56SessionHandler_concept.php
Created March 19, 2014 14:55
Pseudo-code explaining how OOP interface to sessions should work in PHP 5.6
<?php
/**
* How OOP interface to PHP sessions should look like in version 5.6.
*
* @author Andrey Andreev
*
* Notes:
* - NO other classes and/or interfaces are necessary/useful and therefore shouldn't exist.
* - Probably a good idea to consider making SessionHandler an abstract class.
*
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index d20dcc9..95065ff 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -106,10 +106,22 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
public function db_connect($persistent = FALSE)
{
- // Persistent connection support was added in PHP 5.3.0
- $hostname = ($persistent === TRUE && is_php('5.3'))
#!/bin/bash
/sbin/iptables -A INPUT -s "$1" -j DROP
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images\/.+\.(jpg|png|gif)|css\/.+\.(css|jpg|png|gif)|js\/.+\.js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
@narfbg
narfbg / join-multiple.patch
Created June 5, 2012 21:19
CodeIgniter QB join() with multiple conditions
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 7a0ea0c..cefaa77 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -343,8 +343,26 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// in the protect_identifiers to know whether to add a table prefix
$this->_track_aliases($table);
- // Strip apart the condition and protect the identifiers
- if (preg_match('/([\[\w\.]+)([\W\s]+)(.+)/', $cond, $match))
@narfbg
narfbg / valid_email.patch
Created June 7, 2012 09:30
CI_Email::valid_email() hostname validation
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index c70144f..8968a84 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -704,11 +704,37 @@ class CI_Email {
* Email Validation
*
* @param string
+ * @param mixed types of records to check
* @return bool
@narfbg
narfbg / redirect_303.patch
Created June 16, 2012 19:51
CI redirect() HTTP code 303 auto-detection
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 40ce807..add7f72 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -526,7 +526,7 @@ if ( ! function_exists('redirect'))
* @param int
* @return string
*/
- function redirect($uri = '', $method = 'auto', $http_response_code = 302)
+ function redirect($uri = '', $method = 'auto', $code = NULL)
@narfbg
narfbg / fix-empty-rules.diff
Created July 2, 2012 12:41
CodeIgniter Form validation library, empty rules
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 3536241..70421ce 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -459,6 +459,10 @@ class CI_Form_validation {
{
$this->_field_data[$field]['postdata'] = $validation_array[$field];
}
+ elseif ( ! empty($row['rules']))
+ {
@narfbg
narfbg / proxies-fix.diff
Created August 15, 2012 12:08
Subnetted proxies fix
diff --git a/system/core/Input.php b/system/core/Input.php
index 968a42a..c3d8980 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -328,34 +328,42 @@ class CI_Input {
return $this->ip_address;
}
- if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR'))
+ $proxies = config_item('proxy_ips');