Recent Comments
Nov 7

Today I experienced a problem where I had to get the IP address of the visitor. The problem was that the domain name was working through load balancer which was sending requests to another server and $_SERVER['REMOTE_ADDR'] was always returning the IP of the remote server.
That’s why I created a method which is solving this problem:

<?php
function get_ip_address(){
    foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){
        if (array_key_exists($key, $_SERVER) === true){
            foreach (explode(',', $_SERVER[$key]) as $ip){
                $ip = trim($ip); // just to be safe

                if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){
                    return $ip;
                }
            }
        }
    }
}
echo get_ip_address();
?>
May 2

Generally this error happens when mail was hosted on the server at some point, but has since been moved to an external mail server. Qmail will still try to deliver the message locally and fail with this error:
This_address_no_longer_accepts_mail

To fix this edit these files:
vi /var/qmail/control/rcpthosts
vi /var/qmail/control/virtualdomains

Remove the line with this domain from both files then restart Qmail:
/etc/init.d/qmail restart

This will solve the problem and mails will be sent properly.
When you make the changes, send test email with php mail() and then tail /usr/local/psa/var/log/maillog
Hope that this helps! icon smile Plesk qmail failure   This address no longer accepts mail quick fix

Jan 22
Firefox lagging
icon1 admin | icon2 Tech News, XHTML | icon4 01 22nd, 2011| icon3No Comments »

Hi,

I had in the last days. I use Firefox all the time and probably because of the cached files or something else it started to lag when I was browsing in more than 4-5 tabs.
I found good solution solving this problem.

Win 7 solution
1. Clear the whole cache of your browser
2. Go to C:\Users\{USERNAME}\AppData\Roaming\Mozilla\FireFox\Profiles
3. Find the folder of your default profile.
4. Delete all sessiostore*.js files

Restart the browser and then everything should be fine.

Hope this will help you. I made it and now it’s working a few times faster icon smile Firefox lagging .
P.S. I can’t imagine if I had to use Chrome LOL

Jan 18

Hi guys,

I met this problem a few times already and I decided to write about it. I will start and repeat this again: DO NOT USE INTERNET EXPLORER AS YOUR DEFAULT BROWSER

The problem is simple: When you have a flash container which is loading xml data generated from php script, this data won’t be loaded properly in the flash because of missing headers. Of course this happens only with IE. The solution is simple. You should add a piece of code which will check if the requests are coming from MSIE browser and if yes, then you just add additional headers.

Here is the code you have to use before the script output the generated xml

if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
}

Hope this will help you!

Cheers!

Jun 23

I met a problem a few days ago. My partner was trying to compile one very big project which has a lot of components, libraries etc …

He added a new component that we were making and try to compile it. But after the swf was compiled it was empty, there was nothing in it and it was half of the original size which had to be.

We had to find a way to solve this compiling problem and the solution was to increase the heap size of JVM. This is only for CS5

Here is how you can do that:

1. Got to C:\Users\{USERNAME}\AppData\Local\Adobe\Flash CS5\en_US\Configuration\ActionScript 3.0

2. Find a fila called jvm.ini

3. Open the file and find a line -Xmx128m

4. Change this to -Xmx512m

5. Save the file and start Flash CS5

Note: Flash must be stopped in the time you are changing this!

I hope this will work for you and you will be able to compile you big projects icon smile Flash cant compile large .fla files

Cheers!

May 31
RIA Security presentation
icon1 admin | icon2 RIA | icon4 05 31st, 2010| icon3No Comments »

I had to do a presentation a few weeks ago about RIA security. I’m uploading it now so everyone who is interested can download it and read it. I’m really sorry that it’s in Bulgarian, but I will translate it as soon as I have some free time.

Download Ria Security Presentations by Rosen Ivanov

Apr 16

Today I received a feature request related to datepicker. I had to change the way of getting the “today” date. By default the datepicker gets the user’s local date/time.

I had to add a feature that is getting the server’s date/time, but according to a specific UTC offset. That’s why I had to rework a little bit the jquery UI.

Here is the necessary code + example how to use it:

1. Necessary changes in jquery-ui-1.7.2.custom.dev.js:

/* Generate the HTML for the current state of the date picker. */
    _generateHTML: function(inst) {
        //we set today date
        var now = new Date();
       
        //we get the time offset
        var timeOffset = this._get(inst, 'timeOffset');
       
        //we calculate the current time according to the time offset
        var localTime = now.getTime();
        var localOffset = now.getTimezoneOffset() * 60000;
        var utc = localTime + localOffset;
        var utcTime = utc + (3600000 * timeOffset);
        var today = new Date(utcTime);
       
        today = this._daylightSavingAdjust(
            new Date(today.getFullYear(), today.getMonth(), today.getDate())); // clear time
        var isRTL = this._get(inst, 'isRTL');
        var showButtonPanel = this._get(inst, 'showButtonPanel');
        var hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext');
        var navigationAsDateFormat = this._get(inst, 'navigationAsDateFormat');
        var numMonths = this._getNumberOfMonths(inst);
        var showCurrentAtPos = this._get(inst, 'showCurrentAtPos');
        var stepMonths = this._get(inst, 'stepMonths');
        var stepBigMonths = this._get(inst, 'stepBigMonths');
        var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
        var currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
            new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
        var minDate = this._getMinMaxDate(inst, 'min', true);
        var maxDate = this._getMinMaxDate(inst, 'max');
        var drawMonth = inst.drawMonth - showCurrentAtPos;
        var drawYear = inst.drawYear;
        if (drawMonth < 0) {
            drawMonth += 12;
            drawYear--;
        }
        if (maxDate) {
            var maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
                maxDate.getMonth() - numMonths[1] + 1, maxDate.getDate()));
            maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
            while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
                drawMonth--;
                if (drawMonth < 0) {
                    drawMonth = 11;
                    drawYear--;
                }
            }
        }
        inst.drawMonth = drawMonth;
        inst.drawYear = drawYear;
        var prevText = this._get(inst, 'prevText');
        prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
            this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
            this._getFormatConfig(inst)));
        var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
            '<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' +
            ' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
            (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+ prevText +'"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>'));
        var nextText = this._get(inst, 'nextText');
        nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
            this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
            this._getFormatConfig(inst)));
        var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
            '<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' +
            ' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
            (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+ nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>'));
        var currentText = this._get(inst, 'currentText');
        var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
        currentText = (!navigationAsDateFormat ? currentText :
            this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
        var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery.datepicker._hideDatepicker();">' + this._get(inst, 'closeText') + '</button>' : '');
        var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
            (this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery.datepicker._gotoToday(\'#' + inst.id + '\');"' +
            '>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
        var firstDay = parseInt(this._get(inst, 'firstDay'),10);
        firstDay = (isNaN(firstDay) ? 0 : firstDay);
        var dayNames = this._get(inst, 'dayNames');
        var dayNamesShort = this._get(inst, 'dayNamesShort');
        var dayNamesMin = this._get(inst, 'dayNamesMin');
        var monthNames = this._get(inst, 'monthNames');
        var monthNamesShort = this._get(inst, 'monthNamesShort');
        var beforeShowDay = this._get(inst, 'beforeShowDay');
        var showOtherMonths = this._get(inst, 'showOtherMonths');
        var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
        var endDate = inst.endDay ? this._daylightSavingAdjust(
            new Date(inst.endYear, inst.endMonth, inst.endDay)) : currentDate;
        var defaultDate = this._getDefaultDate(inst);
        var html = '';
        for (var row = 0; row < numMonths[0]; row++) {
            var group = '';
            for (var col = 0; col < numMonths[1]; col++) {
                var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
                var cornerClass = ' ui-corner-all';
                var calender = '';
                if (isMultiMonth) {
                    calender += '<div class="ui-datepicker-group ui-datepicker-group-';
                    switch (col) {
                        case 0: calender += 'first'; cornerClass = ' ui-corner-' + (isRTL ? 'right' : 'left'); break;
                        case numMonths[1]-1: calender += 'last'; cornerClass = ' ui-corner-' + (isRTL ? 'left' : 'right'); break;
                        default: calender += 'middle'; cornerClass = ''; break;
                    }
                    calender += '">';
                }
                calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
                    (/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') +
                    (/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') +
                    this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
                    selectedDate, row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
                    '</div><table class="ui-datepicker-calendar"><thead>' +
                    '<tr>';
                var thead = '';
                for (var dow = 0; dow < 7; dow++) { // days of the week
                    var day = (dow + firstDay) % 7;
                    thead += '<th' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
                        '<span title="' + dayNames[day] + '">' + dayNamesMin[day] + '</span></th>';
                }
                calender += thead + '</tr></thead><tbody>';
                var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
                if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
                    inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
                var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
                var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate
                var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
                for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
                    calender += '<tr>';
                    var tbody = '';
                    for (var dow = 0; dow < 7; dow++) { // create date picker days
                        var daySettings = (beforeShowDay ?
                            beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
                        var otherMonth = (printDate.getMonth() != drawMonth);
                        var unselectable = otherMonth || !daySettings[0] ||
                            (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
                        tbody += '<td class="' +
                            ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
                            (otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
                            ((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) || // user pressed key
                            (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
                            // or defaultDate is current printedDate and defaultDate is selectedDate
                            ' ' + this._dayOverClass : '') + // highlight selected day
                            (unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') +  // highlight unselectable days
                            (otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
                            (printDate.getTime() >= currentDate.getTime() && printDate.getTime() <= endDate.getTime() ? // in current range
                            ' ' + this._currentClass : '') + // highlight selected day
                            (printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
                            ((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
                            (unselectable ? '' : ' onclick="DP_jQuery.datepicker._selectDay(\'#' +
                            inst.id + '\',' + drawMonth + ',' + drawYear + ', this);return false;"') + '>' + // actions
                            (otherMonth ? (showOtherMonths ? printDate.getDate() : '&#xa0;') : // display for other months
                            (unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
                            (printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
                            (printDate.getTime() >= currentDate.getTime() && printDate.getTime() <= endDate.getTime() ? // in current range
                            ' ui-state-active' : '') + // highlight selected day
                            '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display for this month
                        printDate.setDate(printDate.getDate() + 1);
                        printDate = this._daylightSavingAdjust(printDate);
                    }
                    calender += tbody + '</tr>';
                }
                drawMonth++;
                if (drawMonth > 11) {
                    drawMonth = 0;
                    drawYear++;
                }
                calender += '</tbody></table>' + (isMultiMonth ? '</div>' +
                            ((numMonths[0] > 0 && col == numMonths[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
                group += calender;
            }
            html += group;
        }
        html += buttonPanel + ($.browser.msie && parseInt($.browser.version,10) < 7 && !inst.inline ?
            '<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
        inst._keyEvent = false;
        return html;
    },

Example how to use it:

$(document).ready(function(){

    $('.datepicker').datepicker({
            numberOfMonths: 1,
            dateFormat: 'mm/dd/yy',
            showButtonPanel: true,
            timeOffset: {/literal}{$current_timezone}{literal}
    });
});

« Previous Entries