Validating CakePHP users from other PHP service

auth-cakephp-php
Nowadays is very common to synchronize different applications, relate them somehow or even share the users accounts.

Working with a framework such as CakePHP make thing easier but at the same time it hides all those actions taking place behind the scenes.

CakePHP automatically hashes the user passwords to secure them and store the hash in the users table of the database. A hashed password with CakePHP 2.3 looks like this: f061c4f1a0b786c3b05dd0013a0230d767l19b77

Continue reading

Disabling JavaScript console in production enviroments and Internet Explorer

We don’t want to show our stuff in public. Having debug information in production doesn’t make any sense.

We usually use the console.log() function of JavaScript for this tasks, and is correct, but we don’t want to comment and uncomment all of those lines every time we move our files to the production server.

Also, console.log() function doesn’t work in most versions of Interet Explorer (8 inclusive if you don’t enable and actually use the development tools functionality).

Having say that, lets fix it in a very simple way:

var console = { log: function() {} };

We have just overwritten the console.log function for an empty function which will not do anything.
Now, if we just want to do it in the production mode, we can add that javascript lines inside a condition like this one:

if(Configure::read('environment') != 'development' || strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE')){
    echo '
        <script type="text/javascript">
            var console = { log: function() {} };
        </script>
   ';
}

And what if we want to disable it with any Internet Explorer version?
We could have done it with jQuery, JavaScript or even HTML comments, but i preferred the PHP method for it:

if(strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE')){ ...

Then we just mix it with the previous code and we have the magic done:

//disable console.log in production and in Internet Explorer
if(Configure::read('environment') != 'development' || strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE')){
    echo '
        <script type="text/javascript">
            var console = { log: function() {} };
        </script>
   ';
}

Creating Url Helper for CakePHP framework

The other day i created a simple helper for CakePHP framework.
I called it URL Helper. It contains the following methods:

  • getRealURL($short)
  • getDomain($url)
  • isSecure($url)
  • getProtocol($url)
  • getPort($url)
  • getExtension($url)
  • addHttp($url)
  • getShortURL($url)
  • isYoutubeVideo($url)
  • getParam($url, $var)
  • getNumberOfParams($url)
  • getParams($url, $vars)
  • isImage($url)
  • getURLFromText($text)
  • eraseURlsFromText($text)
  • shortURLsFromText($text)

Continue reading