Kamis, 23 Juli 2015

PHP : How To Get Date After 30 Days

It is very easy to do, just by using the built-in function of PHP, the name is date function and strtotime function.
Let me show how to do it:

<?php
$result_date1 = date("Y-m-d",strtotime("+30 days"));
// $result_date1 is date after 30 days from current date

$date = "2015-07-23";
$result_date2 = strtotime('+30 days',$date);
// $result_date2 is date after 30 days from 2015-07-23
?>

Rabu, 22 Juli 2015

PHP : How To Hide All Error Message

In PHP error message helps us to debugging an application that we are building, the error message can point us in the file which contained the error. In fact we can know clearly on the line how many errors in our code.

However, please note that the error message can be a security gap in our application if the user can view the message. So I'll give you an example of how to hide all error messages in PHP level.

Put a single line of code below at the very top of your code.
error_reporting(0);
Note: Put the code only if your application is ready to be published, because if you put the code during the development it will be difficult for you in debugging your application and you will often find blank screen.

PHP : Error Reporting Management For Debugging

In PHP we can choose the level of error reports to be displayed or to be hidden. Is that Notice, Warning, Parse, Deprecated, Fatal Error, or we will hide all the error reporting level. We will use the PHP error_reporting function.

Here are some examples of how to use it.
<?php
// Turn off all error reporting level
error_reporting(0);

// Report runtime errors only
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Report all errors
error_reporting(E_ALL);

// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>

PHP : How To Get Day Name By Date

This time I will give a simple example to get the name of the day by date in PHP. Function used is inherited from PHP, which is the date function.
Here is an example of how to do it.
<?php
$dayname_today = date("l"); // Day name of current date

$custom_date = "2015-07-22";
$custom_dayname = date("l",strtotime($custom_date)); // Day name of 2015-07-22 date
?>
Hopefully this short article help you, thank you.

PHP : How To Get IP Address Of Visitor

This is the easiest case in the development of a website or web-based applications using PHP, and it is also often asked, especially for novice developers.
How do I get the ip address of website visitors with php?
$ip_address = $_SERVER["REMOTE_ADDR"];
Now you've got the ip address of your website visitors. Good luck.

PHP : Check If String Contains Specific Words

In the PHP programming algorithm, sometimes we will need to check if in a string containing a particular word. It is not hard to do. In the innate function of PHP, there are functions that can to do this with ease, it is strpos function.

Basically strpos function is used to determine the position of a character or a word or a sentence fragment.

Example 1:

$text = "abcdef";
$pos_a = strpos($text,"a"); // $pos_a = 0
$pos_c = strpos($text,"c"); // $pos_c = 2
$pos_f = strpos($text,"f"); // $pos_c = 5
This function will return the position of specific character or word that we need or return false if not found.

Example 2:

$text = "webattribute.blogspot.com";
if( strpos($text,"webattribute") !== false ){
   // TODO - When specific word found
} else {
   // TODO - When specific wordd not found
}
In the above example, ofcourse the string contains the "webattribute" word in the zero position. And remember that zero is not the same as false (0! == False). Therefore, in the above case, the command will be executed is defined command if the string contains the "webattribute" word.

Hopefully the little knowledge I've shared this useful for you. Thank you.

Selasa, 21 Juli 2015

PHP : How To Validating Email Address

On this occasion, I will give some examples to validate email address with php.
Example 1
$email = $_POST['email_address'];
filter_var($email, FILTER_VALIDATE_EMAIL);
This function will returns the filtered data, or FALSE if the filter fails.
Example 2
<?php
var_dump(filter_var('bob@example.com', FILTER_VALIDATE_EMAIL));
var_dump(filter_var('http://example.com', FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED));
?>
The above example will output:
string(15) "bob@example.com"
bool(false)
Example 3
<?php
$email = $_POST['email_address'];
$valid_email = filter_var($email, FILTER_VALIDATE_EMAIL);
if($valid_email===false){
// TODO - When email address is invalid
} else {
// TODO - When email address is valid
}
?>

PHP : How To Prevent SQL Injection


SQL injection is a code injection technique, used to attack data-driven applications, in which malicious SQL statements are inserted into an entry field for execution (e.g. to dump the database contents to the attacker).
More about SQL Injection

To prevent SQL Injection we have two options, escaping the special characters in the unsafe variable, or using a parameterized query. Both would protect you from SQL injection. The parameterized query is considered the better practice, but escaping characters in your variable will require fewer changes.

Here the example

Example 1 : Escaping Special Characters

$unsafe_variable = $_POST["user-input"];
$safe_variable = mysql_real_escape_string($unsafe_variable);
mysql_query("INSERT INTO table (column) VALUES ('" . $safe_variable . "')");
More about mysql_real_escape_string function.

Warning: As of PHP 5.5.0 mysql_real_escape_string and the mysql extension are deprecated. Please use mysqli extension and mysqli::escape_string function instead

Example 2 : Using Parameterized Query

To use the parameterized query, we need to use MySQLi rather than the MySQL functions. 
$mysqli = new mysqli("server", "username", "password", "database_name");

// TODO - Check that connection was successful.

$unsafe_variable = $_POST["user-input"];

$stmt = $mysqli->prepare("INSERT INTO table (column) VALUES (?)");

// TODO check that $stmt creation succeeded

// "s" means the database expects a string
$stmt->bind_param("s", $unsafe_variable);

$stmt->execute();

$stmt->close();

$mysqli->close();
Whatever the reason, the practice of sql injection is highly detrimental action. This would be a very serious concern for companies with a high level of data confidentiality.

Thank you, hopefully this article useful.

Rabu, 15 Juli 2015

Free Download Adobe CS3 Portable (about 48M)


Adobe Photoshop is one of the tools most widely used by designers worldwide. Many advantages of Adobe Photoshop than other tools make this program are very large in size and performance. Therefore, Adobe Photoshop require high specification device used.

But for those who have a computer with limited specifications, do not worry because I'll share a link to download Adobe Photoshop CS3 portable with a size of only about 48M. Interesting is not it?

Chek it out: https://docs.google.com/file/d/0B2_DQmuprDoiWWhkUE9ZOVNmWEk
Copyright @ 2013 Web Attribute. Designed by Templateism | Love for The Globe Press