Latest Updates

View More Articles

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
}
?>
Copyright @ 2013 Web Attribute. Designed by Templateism | Love for The Globe Press