PHP

26
Sep
2011

Closing Tag in PHP

If file consists only of php code (without HTML code), then the best practice is to omit closing tag (?>).

Although closing tag rarely causes any problems (the most common - accidentally putting space character after "?>" can causes sending a HTTP headers and then if you want to send headers manually for example for the redirect purposes, it's simple doesn't work 'cause headers has already been sent), nevertheless giving up to use closing tag is a rather good practice in php.

Generally speaking, if closing tag is not mandatory, so why we need to use it?

So, in case

  1. <?php
  2. echo 'Hello, world!';
  3. ?>
  4. <html>something</html>

we must using closing tag for keeping apart php and html code.

But in this case

  1. <?php
  2. echo 'Hello, world!';

closing tag should be omitted.

And in this case

  1. <html>something</html>
  2. <?php
  3. echo 'Hello, world!';
  4. ?>

you can omit closing tag or not on your own discretion. Though, it's better not to omit "?>" so the code become more clear to understand.

Category: 
0
09
Sep
2011

MD5 Hashing and Salt

md5 hash can be easily cracked by using Rainbow Tables. So, pure md5 hash must be using only for checking data integrity and not for security purposes.

However, by using "salt" it's become impossible to reverse md5 and get the original data, which means that this method can be used to encipher passwords and other important information.

Salt is just a some random bits, for instance some text or even image.

So, instead of

  1. <?php
  2. $pwd = 'my_pwd';
  3. $hash = md5($pwd);
  4. ?>

we should use something like this

  1. <?php
  2. $salt = 'some text';
  3. $pwd = 'my_pwd';
  4. $hash = md5($pwd . $salt);
  5. ?>

or like this

  1. <?php
  2. $salt = 'some text';
  3. $pwd = 'my_pwd';
  4. $hash = md5(md5($pwd) . $salt);
  5. ?>

or even like this

  1. <?php
  2. $salt = 'some text';
  3. $pwd = 'my_pwd';
  4. $hash = md5(md5($pwd . $salt) . $salt);
  5. ?>
Category: 
8