Articles

Find user’s timezone with PHP and Ajax

In PHP on October 14, 2011 by patrellery

Here’s a simple function to find out what is the user’s timezone in PHP


<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
if("".length==0){
var visitortime = new Date();
var visitortimezone = "GMT " + -visitortime.getTimezoneOffset()/60;
$.ajax({
type: "GET",
url: "http://domain.com/timezone.php",
data: 'time='+ visitortimezone,
success: function(){
location.reload();
}
});
}
});

and then on your php file:
<?php
session_start();
$_SESSION['time'] = $_GET['time'];
?>

Advertisements

Articles

$this vs $(this) in jQuery

In jQuery on October 11, 2011 by patrellery

How many times we try to use this and we need to use $(this) and vice versa? Well here’s a quick explanation on how to differentiate these two objects
Read More »

Articles

Most efficient way to empty an element with jQuery

In jQuery on October 9, 2011 by patrellery

There’s more than one way to empty an element with jQuery.

$(selector).html('');
$(selector).text('');

These are all valid but might not be as efficient as the empty() function.

$(selector).empty();

This is definitely the most clear way, and almost definitely the most efficient because by definition these call the empty() in their implementation. In addition, they invoke html parsers rather than just dealing with dom nodes like the other methods.

So go check your code now!

Articles

How secure is .htpasswd

In Security on October 7, 2011 by patrellery Tagged: ,

Several things to notice:

Adding security in a .htaccess can always be done without the .htaccess, by using instructions in the main configuration (or the virtualhost configuration). It will go faster (if you remove completly support for .htaccess with AllowOverride None) and you wont get the risk of someone altering your .htaccess.
Read More »

Articles

How to clear redis keys

In PHP on October 2, 2011 by patrellery Tagged:

The other day we found a big issue on our development platform and we had to clear Redis memory/Keys to make sure we re-import valid data to our database.
Read More »

Articles

How to use jQuery to extract a URL parameter from a string

In jQuery on October 1, 2011 by patrellery

Many development languages, such as ASP, PHP, Python, Objective-C etc.., has their own function to parse and extract URLs components.

Where is the jQuery one? That will be very helpful if we don’t rely on the server to parse any URL and we let jQuery do it for us.

Read More »

Articles

Split string by delimiter in PHP

In PHP on September 29, 2011 by patrellery Tagged:

Here’s a quick tip to split a string using the pipe (|) delimiter in PHP. Let’s say you have a log or some sort of non usual string you want to split, such as:

$str = 'A|B\|B|C\\|D\\\|D';

You want this to look like:

$array[0] => 1
$array[1] => 2\|2
$array[2] => 3\\
$array[3] => 4\\\|4

Read More »