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 / 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 / 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]

Keybase proof

I hereby claim:

  • I am AndreiTelteu on github.
  • I am andreitelteu (https://keybase.io/andreitelteu) on keybase.
  • I have a public key whose fingerprint is 6D38 3885 8AB5 904A 4933 C7BA 101C E7AA 653C DAB7

To claim this, I am signing this object:

@AndreiTelteu
AndreiTelteu / Ajenti Web Install Ubuntu .md
Last active August 29, 2015 14:17
Install Ajenti Web Ubuntu Install

Instead of searching on the ajenti.org website every time i want to install it, i copy and paste the code from this page.

wget -O- https://raw.github.com/Eugeny/ajenti/master/scripts/install-ubuntu.sh | sudo sh

You may need apt-get remove apache2, and finaly

apt-get install ajenti-v ajenti-v-nginx ajenti-v-mysql ajenti-v-php-fpm php5-mysql

service ajenti restart

@AndreiTelteu
AndreiTelteu / CakePHP function for calling WP-API .md
Last active August 29, 2015 14:17
Protected function for calling WP REST API plugin
  1. Install the json rest api wordpress plugin.

  2. Include the following function in app/Controller/AppController.php in your CakePHP instalation.

    	protected function _wpAPI($method='get', $url='/', $data=null)
    	{
    		App::uses('HttpSocket', 'Network/Http');
    		$http = new HttpSocket();
    		
    		$http->configAuth('Basic', 'admin', 'password');