Skip to content

Instantly share code, notes, and snippets.

View AndreiTelteu's full-sized avatar

Andrei Telteu AndreiTelteu

View GitHub Profile

Get the real IP of a visitor, when your website is using CloudFlare

<?php
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
	$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
?>

Credits: http://stackoverflow.com/users/1279594/sharp12345

<?php
$baseUrl = $_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'];
if ($_SERVER['SERVER_PORT'] != '80') $baseUrl .= ":".$_SERVER['SERVER_PORT'];
define("BASE_URL", $baseUrl);
<?

A input group with 2 text inputs / demo here: http://jsfiddle.net/rjj0x1sm/

<div class="input-group" id="unified-inputs">
  <input type="text" class="form-control" placeholder="Input1" />
  <input type="text" class="form-control" placeholder="Input2" />
</div>

This configuration you have to pass in the Custom configuration textarea for hosting CakePHP Framework on Ajenti panel.

Please note that in the general tab your Path must end with "app/webroot/".

    # Not found this on disk?
    # Feed to CakePHP for further processing!
    if (!-e $request_filename) {
        rewrite ^/(.+)$ /index.php?url=$1 last;
 break;
@AndreiTelteu
AndreiTelteu / CakePHP Bootstrap Pagination .md
Last active August 29, 2015 14:06
Bootstrap-friendly pagination in CakePHP

Bootstrap-friendly pagination in CakePHP

Put this in your controller .php

<?php
$this->paginate = array(
	'order' => array('field' => 'asc'),
	'limit' =&gt; 1,
@AndreiTelteu
AndreiTelteu / Remove Accent .md
Last active December 21, 2018 13:36
Remove the accent from a string or array
function remove_accent($str) {
    $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', '
@AndreiTelteu
AndreiTelteu / Mark a word .md
Last active January 25, 2022 22:50
Mark a word with <mark>

You can easily mark a specified word (or array of words) in a string.

<?php
function mark($pattern, $source) {
    if (is_array($pattern)) {
        $finalPatterns = array_map(function ($value) { return "/(".preg_quote($value).")(?![^<]*>|[^<>]*<\/)/i"; }, $pattern);
    } else {
        $finalPatterns = "/(".preg_quote($pattern).")(?![^<]*>|[^<>]*<\/)/i";
 }
@AndreiTelteu
AndreiTelteu / CDN for Bootstrap IE Compatibility .md
Last active August 29, 2015 14:06
Bootstrap compatibility in IE, from MaxCDN

Add this code before </head>:

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
@AndreiTelteu
AndreiTelteu / OpenShift NginX PHP-FPM configuration for Wordpress .md
Last active November 3, 2015 08:58
The configuration needed for runing a Wordpress (standard/multisite) app over NginX PHP-FPM on OpenShift.
  1. Create an app/gear on OpenShift with this cartidge: OpenShift Nginx PHP-FPM Cartridge

  2. Open the file: <your-app-folder>/config/nginx.d/default.conf.erb, earse all the content, and paste this instead:

server {
  root              <%= ENV['OPENSHIFT_REPO_DIR'] %>/php;
  listen            <%= ENV['OPENSHIFT_PHP_IP'] %>:<%= ENV['OPENSHIFT_PHP_PORT'] %>;
  server_name       <%= ENV['OPENSHIFT_APP_DNS'] %>;
  index             index.php index.html index.htm;
@AndreiTelteu
AndreiTelteu / Redirecting WWW to NON-WWW the right way .md
Last active August 29, 2015 14:10
How to redirect www to non-www in the right way.

Add this in your .htaccess file:

	RewriteCond %{HTTPS} off
	RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
	RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
	
	RewriteCond %{HTTPS} on
	RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
	RewriteRule ^(.*)$ https://%1/$1 [R=301,L]