Posts marked with "Function" in tags

E-Mail Verification Script In PHP Using Mailgun API

As years goes, so does the increase in SPAM on the web. Most users sign up on services with a fake E-Mail. They might even use other’s E-Mail for signing up. This is a big problem, because when you send an email to the signed up user, it goes to the wrong guy. So, you should verify user’s email before signing them up. You might think that it would cost database memory. Don’t worry, because my script won’t require storage of verification codes on database.

... [READ MORE]

Image Handling On Client Side With Base64 In PHP

Every website needs images. It make the site attractive and beautiful. But sometimes, images won’t get loaded. The latest **Browsers **have a feature that generates image on a base64 string. Most of the browser have it. In this post I’m going to describe the way to use base64 in displaying images on a website.

What’s base64 ?

Base64 is a encrypting method which is available in many languages. It can be used for encrypting and decrypting. It is not like other hash functions (MD5, SHA 256, SHA 512). Unlike other hash methods, a base64 encrypted string can be directly decrypted. But other hash functions can only be used for checking a value.

... [READ MORE]

Generating Random String in PHP

In PHP you can generate random number by using rand function, but there is no specific function to generate a random text or string. In this post I’m going to show the function that will generate a random string of length mentioned.

Here is the function:

function rand_string($length) {
 $str="";
 $chars = "subinsblogabcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 $size = strlen($chars);
 for($i = 0;$i < $length;$i++) {
  $str .= $chars[rand(0,$size-1)];
 }
 return $str;
}

Usage

To generate a random string use rand_string() function with the parameter of length of the to be generated string. Here’s an example:

... [READ MORE]

Add GET or POST parameters on include files in PHP

If you want to add GET parameters or POST parameters to files loading using include function in PHP then you should know the following:

It’s not possible. But it is in a different way.

If you are adding GET parameters to file name like the following, then it won’t work:

The above code won’t load the file, because PHP Include function only looks for files, it won’t send any parameters. It will search for file.php?user=subin in the directory for the case above. You can make it work in a different way.

... [READ MORE]

How to get Current Time and date in Javascript

This tutorial will help you to get current date and time at which the function is executed. Here is the function:

function ctime(){
var currentdate = new Date();
var time=currentdate.getFullYear()+"-"+(currentdate.getMonth()+1)+"-"+currentdate.getDate()+" "+currentdate.getHours()+":"+currentdate.getMinutes()+":"+currentdate.getSeconds();
return time;
}

Just print out ctime() function to get the date and time in the format YEAR/MONTH/DAY HOUR:MINUTE:SECOND 

Explanation :

new Date() function prints out the current date and time in a disorderly way. You can order it in any way as I did in the time() function.
currentdate.getFullYear() will get the year from new Date() which is in the variable currentdate
currentdate.getMonth() will get the month from new Date() function. The program adds 1 to the month because Javascript always count the month from . So we should add a +1.
currentdate.getDate() will get the day of the month in which the function is executed.
currentdate.getHours() will give the Hour of the time.
currentdate.getMinutes() will give the Minute in which the script is executed.
currentdate.getSeconds() This function will give the seconds of the time at which the script is executed.
... [READ MORE]

The best age calculation code in PHP

Age calculation is a tricky calculation especially in Programming Languages. I’m going to tell you a simple way to find out age in PHP. This is a simple function that will calculate age if it is given a birthday date in the format date/month/year. For example : 20/01/2000 or 04/12/1990
Here is the function :

function age($birthday){
 list($day,$month,$year) = explode("/",$birthday);
 $year_diff  = date("Y") – $year;
 $month_diff = date("m") – $month;
 $day_diff   = date("d") – $day;
 if ($day_diff < 0 && $month_diff==0){$year_diff–;}
 if ($day_diff < 0 && $month_diff < 0){$year_diff–;}
 return $year_diff;
}

... [READ MORE]

Follow/Subscribe

Telegram 

Mastodon  Twitter

GitHub GitLab

Subdomains

Demos  Lab

Past

This blog was once on WordPress. Now a static site. See source code on

GitLab