Archiv der Kategorie ‘PHP‘

 
 

PHP: Use the ternary operator in PHP

A good program is sometimes equalized with few lines of code. But how do we program this way? One step is using the ternary operator...

Den ganzen Beitrag lesen...

PHP: Correct Hashing Passwords in PHP

I found this article about password hashing in PHP on Twitter and found a few serious points that are not fully correct in this article.

Den ganzen Beitrag lesen...

PHP: Easy to use and secure PHP hashing Class

Why

I created this class because there are too many people still saving simple md5 instead of more secure hashes.
The class should be fully PHP4 and PHP5 compatible and very easy to use. But also extended usage on its complex methods is possible.

Example

The usage of the class should be straight forward.
If you just want to use it, use the methods hash() and check().
EXAMPLE:

$secure_hash = new secure_hash;
$hash = $secure_hash->hash('pass');
if($secure_hash->check($hash, 'pass'))
  echo "Password fits to hash.";
else
  echo "Password does NOT fit to hash.";

That is all you need to know for just using it, but i have to tell, you will miss something important if you stop reading here.

Den ganzen Beitrag lesen...

PHP: Create your own url shortener with this easy to use PHP Class

After using Twitter some time now, i saw several URL shortening services and a few scripts that would do the work. But i did not see any PHP Class for doing this job easily. So i wrote one myself ...

Den ganzen Beitrag lesen...

Benchmark: APC vs. MySQL MEMORY fetching Speed

I once wrote a article about APC and MySQL MEMORY table caching and found out that APC needs very much memory compared to MySQL MEMORY. Now i did a short benchmark to check out the fetching speed of these two solutions with a interesting result.

Den ganzen Beitrag lesen...

PHP: Best bugreport EVER!

This is the best PHP bug rebot EVER! Just read it:
http://bugs.php.net/bug.php?id=48669

Den ganzen Beitrag lesen...

PHP: Benchmark isset() or array_key_exists() ?

The Twitter user caioariede postet that you should array_key_exists() instead of isset(). He did not say why so i tried to check performance first and came to interesting results...

Den ganzen Beitrag lesen...

PHP: foreach vs. while vs. for - The loop battle!

PHP has just one kind of array, it does not have separate lists, hash or maps, they are all combined in a "array". Iterating over such a array is a very common part so doing it wrong can lead to less performance.
In the following article i will do a short test which loop is the fastest.

Den ganzen Beitrag lesen...

PHP: PHP 5.3.0 - Short Ternary Operator

With the Realease of PHP 5.3 have come very much little new details, on of them is the short ternary operator wich annoyed me for a long time because you have to use it with 3 subjects.
Before PHP 5.3.0 this was the only way it could be done:

$result = ($if == 3) ? $than : $else;

Now in PHP 5.3.0 you can write:

$result = ($if == 3) ?: $else;

There is one problem i see here.
I cant use this in my public projects because it will make my code >= PHP 5.3 dependent wich is NOT an Option. But this mixed with the fact that namespaces are now available with PHP 5.3, it will my namespaced code always PHP 5.3 dependent.

PHP: APC oder MySQL MEMORY Table für temporären Cache?

mysql_logoBei einem aktuellen Projekt wurde APC eingesetzt um tausende kleinere Variablen zu cachen da es sich nicht lohnen würde diese in einer persistenten Datenbank zu speichern. Da der 30MB große APC Cache jedoch recht schnell voll wurde habe ich ein paar Nachforschungen angestellt, dabei bin ich zu dem Schluss gekommen dass APC für das Speichern von einzelnen kleinen Variablen viel zu viel Speicher verschwendet.

Den ganzen Beitrag lesen...