February 12, 2014

PHP Helper Function: get_function_static()

PHP Helper Function: get_function_static() Description: This function returns the name of calling function. You can specify the $index param to retrieve nth level of calling functions. function get_function_static($bt, $index=0) { if (isset($bt[$index][‘function’])) return $bt[$index][‘function’]; else return false; } Usage $bt = debug_backtrace(); $parent_function = $this->get_function_static($bt, 1);

February 1, 2014

Severity: 4096, Object of class stdClass could not be converted to string

Severity: 4096, Object of class stdClass could not be converted to string Error Description: A PHP Error was encountered Severity: 4096 Message: Object of class stdClass could not be converted to string Filename: libraries/Parser.php Line Number: 101 Solution: if (is_array($val)) { $template = $this->_parse_pair($key, $val, $template); } elseif(is_object($val)){ $val = (array)$val; $template = $this->_parse_pair($key, $val, […]

January 31, 2014

PHP Regular Expressions to Extract Images from HTML Content

PHP Regular Expressions to Extract Images from HTML Content //preg_match_all(‘/<img[^>]+>/i’, $description, $img); //preg_match_all(‘/src=”([^”]*)”/’, $description, $img); preg_match_all(‘@<img.*src=”([^”]*)”[^>/]*/?>@Ui’, $description, $img);

December 27, 2013

PHP – Helper Function – clean_xhtml

PHP – Helper Function – clean_xhtml if ( ! function_exists(‘clean_xhtml’)) { function clean_xhtml($string) { /*$string = preg_replace(‘@<iframe[^>]*?>.*?@siu’, ”,html_entity_decode($string)); $string = preg_replace(‘@<p[^>]*?>.*? @siu’, ”,$string); return $string;*/ $string = ereg_replace(“<[^>]*>”, “”, $string); $string = preg_replace(“@<p[^>]*?>.*? @siu”, ”,$string); return $string; } }

July 8, 2013

PHP Function – Time Difference or Time Ago

PHP Function – Time Difference or Time Ago function _ago($time_to, $time_from = 0) { if($time_from==0) time(); $rtc = 60*60*24; //ROUND THE CLOCK $total_weeks = 52.177457; //ESTIMATE NO. OF WEEKS $years = (int)((($time_from – $time_to)/(7*$rtc))/$total_weeks); $rem = (int)(($time_from-$time_to)-($years * $total_weeks * 7 * $rtc)); $weeks = (int)(($rem)/(7*$rtc)); $days = (int)(($rem)/$rtc) – $weeks*7; $hours = (int)(($rem)/3600) – […]

January 12, 2013

Session out issue in codeigniter

Session out issue in codeigniter Note: wdwd = websitedesignwebsitedevelopment In fact CI is managing the session with cookies and when you mention your domain in config file so it creates the cookies with that identity. It is already clear that we can have sub-domains as well. So with www. and without www. cookies will have […]

September 17, 2012

Cross-site request forgery (CSRF) Updated

Cross-site request forgery (CSRF) Updated public function csrf_verify() { // If no POST data exists we will set the CSRF cookie if (count($_POST) == 0) { return $this->csrf_set_cookie(); } if((isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && $_SERVER[‘HTTP_X_REQUESTED_WITH’] == “XMLHttpRequest”) || isset($_SERVER[‘HTTP_REFERER’])) { if(isset($_SERVER[‘HTTP_REFERER’])) { $parse_url = parse_url($_SERVER[‘HTTP_REFERER’]); if($parse_url[‘host’]!=$_SERVER[‘HTTP_HOST’] && !in_array($parse_url[‘host’], array(‘apps.facebook.com’))) { $this->csrf_show_error(); } else { //echo ‘Safe’; //echo ‘Host […]

September 14, 2012

Cross-site request forgery (CSRF) – Ajax Fix

Cross-site request forgery (CSRF) – Ajax Fix CSRF Security Class is great practice which is not really in practice commonly. The reason is workload of the scope of the project. Developers mostly don’t care about the form class of the CI and 20% or less people use form helper to generate 100% forms in their […]